XPath Functions

   



A Simple Stylesheet

Let's look at the following specific example of an XSL stylesheet:

Listing A.1 A simple stylesheet

start example
<?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 ---> 
end example

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.



   



Fundamentals of SVG Programming. Concepts to Source Code
Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
ISBN: 1584502983
EAN: 2147483647
Year: 2003
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net