A Leading Slash ( ) Is Significant

   



Counting Qualified Elements

Listing A.5 displays the contents of a stylesheet that counts and then displays the number of chapters in the file book.xml.

Listing A.5 countChapters1.xml

start example
<?xml version="1.0"?> <xsl:stylesheet      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      version="1.0"> <xsl:template match="/">   Chapters:  = <xsl:value-of select="count(//chapter)"/>   All desc:  = <xsl:value-of select="count(//desc)"/>   Book desc: = <xsl:value-of select="count(//chapter/desc)"/> </xsl:template> </xsl:stylesheet>
end example

Remarks

Listing A.5 demonstrates the use of the count function in XSL and the '//' in order to count the number of chapters in the book defined in book.xml. You already know that the desc element can refer to the description of the book as well as the description of each chapter in the book. Now you know how to distinguish these two types of elements; that is, '//desc' refers to any desc element whereas '/chapter/desc' refers to a desc element that is a child of a chapter element.



   



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