|
|
Let's look at the following specific example of an XSL stylesheet:
Listing A.1 A simple stylesheet
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <xsl:apply-templates> </xsl:template> </xsl:stylesheet> <!--- There are no other templates here, so default rules will be applied instead --->
There is nothing obvious about the meaning of the code in the preceding XSL stylesheet. In fact, if you've never seen XSL, it probably looks arcane and mysterious (and perhaps even useless). The first two lines are directives, and the rest of the XSL contains a single template that matches the root element of an XML document:
<xsl:template match="/"> <xsl:apply-templates> </xsl:template>
When you apply an XSL stylesheet to an XML document, the '/' means 'match the root element of the XML document,' which is required in every well-formed XML document. Think of this template as the 'entry point' into the other templates defined in the XSL stylesheet. What happens after that? In our case, you see the following:
<xsl:apply-templates>
Since there is no other template in this XSL stylesheet, the 'default rules' are invoked, one of which causes all the text in the XML file to be printed. If your XML document contains one megabyte of 'pure data,' then you will see that megabyte of data displayed on the screen. This is an example of an extremely compact XSL stylesheet that can generate copious amounts of output, depending on the amount of raw data in the XML document in question.
|
|