[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Proper syntax for counting all prior nodes in XPat
> How can my XSL count all the preceding nodes? For example, when my template > is processing the <LINE>Test 3</LINE>, I want to count all nodes before it, > which would be 2 <LINE>s, 2 <PAGE>s, 2 <SECTION>s, 1 <CHAPTER>, and 1 <DOC>. The template below will count the LINE, PAGE, SECTION, CHAPTER, and DOC elements that precede each LINE element by using the 'preceding' axis and the count() function. Keep in mind that in your example the count of DOC elements will always be 0, because the only DOC element is the one used as a document element and therefore enclosing the whole document, and when element A is inside of element B, element B does not precede element A, even if element B's start-tag does precede element A's start-tag. For one element to be in another's 'preceding' axis, the whole thing has to precede that element, not just its start-tag. Bob DuCharme www.snee.com/bob <bob@ snee.com> see http://www.snee.com/bob/xsltquickly for info on new book "XSLT Quickly" from Manning Publications. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <xsl:template match="LINE"> LINE contents: <xsl:apply-templates/> preceding LINE elements: <xsl:value-of select="count(preceding::LINE)"/> preceding SECTION elements: <xsl:value-of select="count(preceding::SECTION)"/> preceding PAGE elements: <xsl:value-of select="count(preceding::PAGE)"/> preceding DOC elements: <xsl:value-of select="count(preceding::DOC)"/> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|