1. Discuss how XSL can be used to generate XHTML?
XSL stands for Extensible Style Sheet Language which defines the presentation and transformation of a XML document.XSL was designed specifically for XML and although it is similar to CSS, it is able to manipulate structure in XML documents much better than CSS. The processing of an XSL style sheet, being applied to an XML document, has to be begin with a XML processor. The processor reads the documents and processes it into important information which is called nodes.
XSL consists of 3 fundamental technologies
XSLT - The only component that is supported by current web browsers, and allows the transformation of XML documents using style sheet code from language to another.
XSLO-FO - This language focuses on the styling and formatting of XML documents. Although not a great option for XML documents that are for web browsers due to the support issue, it is effective in the styling of XML documents for printing. A good use for this is that you can convert an XML document into a PDF file Adobe Acrobat.
XPath - This is an expression language that is used to navigate through parts of an XML document, and is very different to its counterparts as it isn't implemented as an XML language.
HTML the hyper text markup language is not a XML based language therefore does not meet the standards of XML. A stricter version of HTML was introduced that adheres to the standards of XML called XHTML.
To be able to transform XML into XHTML it can be done so by using XSLT, I started with using one of my previously created XML documents which lists my top ten CD’s. I then went on to create a XSL style sheet with both docs, it’s important to use the correct declarations. This was inserted in my XSL file at the very top.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
I then went on to create the style sheet, which some of my code is as follows:
<xsl:template match="/">
<html>
<body>
<h2>My Top Ten CD's</h2>
<table border="4">
<tr bgcolor="#green">
<th>Album</th>
<th>Artist</th>
</tr>
<xsl:for-each select="MUSICDATABASE/CD">
<tr>
<td><xsl:value-of select="ALBUM"/></td>
<td><xsl:value-of select="ARTIST"/></td>
</tr>
</xsl:for-each>
</table>
To round things off I linked the style sheet to my XML document using the below code. It worked successfully as when I opened my XML document with Internet Explorer a table was shown with the selected formatting I created in the XSLT Style sheet. As shown the xls is a file extension, and is its own separate text file that has to be linked to the XML document
2. How can XML be styled using CSS? What are the strength and weaknesses of using CSS?
XML can be styled using CSS, Cascading Style Sheets and it is often a good idea due to its compatibility with web browsers. However this is only a good idea if the task at hand is to solely display content rather than control features like XSLT is able to do to an XML document. When used with XML, CSS allows the control of formatting and positioning and does not concern itself with transforming and processing XML code.
CSS files are stored in seperated text files and have the extension .css, therefore in order for a CSS to function with the XML document it must be connected to that document. The processing instruction is shown to the left.
<----------------------------
Example CSS text file
favmusic
{
display:block;
color: red
background-color: black;
text-align:left;
}
CD
{
font-family: Georgia;
font-size:14pt;
}
ALBUM
{
font-family: Comic Sans;
font-size: 12pt;
}
SONG
{
font-family: Comic Sans;
font-size:12pt;
}
.................................
.................................
Example XML document
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="favmusic.css"?>
<!DOCTYPE favmusic SYSTEM "favmusic.dtd">
<favmusic>
<CD>
<ALBUM>Unthinkable</ALBUM>
<SONG>Sleeping With a Broken Heart</SONG>
............................................................
............................................................
</CD>
</MUSICDATABASE>
The product of this when viewed in a web browser would be a black background with the red text and different font size's according to what is marked on the CSS. Such a CSS could be altered numerous times to a person's desire eg. adding borders, tables, layout properties etc...
Strengths of CSS
- Powerful
- Web browser compatible
- Code is simple to understand
- The ability to reuse existing code
- Flexibility in determining the appearance of the XML document
Weaknesses of CSS
- Printing issues of XML documents
- Limited to only styling documents
- Security issues, as they can easily be overridden
3. How can XML be styled using XSLT style sheets? What are the strengths and weaknesses of using XSLT style sheets?
Extensible Stylesheet Language Transformation XSLT is an XML based styles heet soley designed for the use with XML documents. It is an XML based markup language with contains its own attributes and elements that are used yo create the XSLT style sheets. XSLT style sheets can be used to do simple transformations such as sorting content into a desired order to the transformation of content into a different XML language. XSLT style sheets have two types of information that they are classed by instructions and literals.
Instructions - These are the elements and attributes of the XSLT that describe how the XML content is to be transformed
Literals - These are static pieces of information that are not processed and are placed directly in the output document
The output document will be the instructions which delivers the content and the literals are placed throughout the XML document.
Example Code:
Having a root template, controls the way in which other templates are displayed :<xsl:template match="/">
This line of code is used to merge the content into the style sheet by the use of literals <td><xsl:value-of select="ALBUM"/></td>
Strengths
- Powerful
- XML data can be merged easily
- In XML databases queries can be returned
- Resilient to changes as it is template based
Weaknesses
- Values of variables cannot be altered
- Complicated business rules are difficult to implement
- Memory issues can lead to Performance issues
4. How can XSLT be used (a) to transform an XML structure and (b) to sort the contents of an XML document?
Continuing from the above Post....
XSLT is ideal when XML documents need to be changed into different formats to be compatible with different applications and devices. This is common in use with web browsers or the need to change XML into XHTML for the benefit of a web browser or application.
XSLT can be extremely useful when XML's structure prevents an application accepting the XMLs structure data. The necessary data may be there, however the XML structure may not be permitted by the application, the solution is XSLT to alter the structure in a way that the application understands.
The Transformation process
A parsed document is loaded into a DOM tree structure. The XML document structure is then taken from an XSLT processor who matches the nodes against the template
XSLT Template
Templates in XSLT are used to process and create the structure that is to be outputted. In creating a template its necessary to use the xls:template element and the match attribute <xls:template match= "/">.A set of nodes are attained by the match attribute being assigned to a pattern or expression. From the example above the value is nothing but a forward slash, this is the default for identifying the documents root node .
As mentioned in the question three's answer the root node can be included if there is a desire to manage the content of more than one template, if this is not the case, then a root node is not necessary and the XLS processor will still apply the style sheet. Specific portions of a XML document can be transformed by the use of multiple style sheets. Nodes can be specified in more detail using XPath which deals with the addressing of portions of data in an XML document and allows advanced node selections. Nodes are processed in XSLT using several pre defined elements. These elements can be used to sort content before displaying, the sorting element is shown as xsl:sort, allowing the sorting of nodes to a specified criteria, following a key, the key is a pattern or expression highlighting the information in the set.
5. Discuss the notion of Xlink. What is its purpose and how do you use it?
To be able to carry out advanced linking between XML documents, Xlink is a great collection of technologies to do this. Xlinks allows data to be embedded in a Document and allows a wide range of data at that, however it is not as popular as W3C intended it to be. Two resources can be connected to a link in one document by the use of links with Xlink which is very useful. These are out of line links, and is useful when you are unable to edit target docs and the source. This will introduce link repositories which is a database of links describing connections of use between resources on the web, making this a practical necessity.
The other linking element supported in XLink is an inline link, which allows its content to serve as one of the links included resources. The content serves as the source for the desired link. XPointer and XPath makes XML links possible and is compulsory as without them its not possible.
Xlinks Attributes
These are the standard attributes used to establish linked elements in XML docs
These are used to create linked elements: (the functions are self explanatory)
Each attribute can have numerous value, example the show element holds three main values new, replace and embed
How to use an Xlink
<?xml version="1.0"?>
<homepage xmlns:xlink="http://www.hiphopworld.com/news/xlink">
<Hip Hop xlink:type="simple" xlink:href="http://www.hiphopworld.com"> ” Number one choice for all the latest news in Hip Hop“</ Hip Hop >
</homepage>