|
|
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
<?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>
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.
|
|