Subject: Re: [xsl] Count of previous nodes until a child node of a previous node is found with certain attribute value From: David Carlisle <davidc@xxxxxxxxx> Date: Sat, 26 May 2007 22:25:58 +0100 |
Michael> David's solution is probably the best that can be done in 1.0. or more exactly, XPath 1. If the lists were long enough that the repeated look back along the sibling axis was a concern, I'd probably re-arrange things to step along one at a time using xslt rather than try to do it all with a single xpath. David <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="body"> <xsl:apply-templates select="p[1]"/> </xsl:template> <xsl:template match="p"> <xsl:param name="c" select="0"/> p: <xsl:value-of select="normalize-space()"/>, count <xsl:value-of select="$c"/> <xsl:apply-templates select="following-sibling::p[1]"> <xsl:with-param name="c" select="$c+1"/> </xsl:apply-templates> </xsl:template> <xsl:template match="p[component/@name='newpage']"> <xsl:apply-templates select="following-sibling::p[1]"/> </xsl:template> $ saxon pn.xml pn2.xsl <?xml version="1.0" encoding="utf-8"?> p: text, count 0 p: text2, count 1 p: text3, count 0 p: text4, count 1 p: text5, count 2 p: text6, count 3 p: text7, count 0 p: text8, count 1 p: text9, count 2 ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Count of previous nodes u, Michael Kay | Thread | Re: [xsl] Count of previous nodes u, Mukul Gandhi |
RE: [xsl] Count of previous nodes u, Michael Kay | Date | Re: [xsl] Grouping and Numbering, Abel Braaksma |
Month |