[Home] [By Thread] [By Date] [Recent Entries]
Below is another XSLT 1.0 solution:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:template match="body"> <xsl:text>p node value Count
</xsl:text> <xsl:apply-templates select="p[not(component)]" /> </xsl:template> <xsl:template match="p">
<xsl:variable name="text" select="normalize-space()" />
<xsl:variable name="x">
<xsl:call-template name="findCount">
<xsl:with-param name="prev-p" select="preceding-sibling::p[1]" />
<xsl:with-param name="result" select="0" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$text" /><xsl:text> </xsl:text><xsl:value-of
select="$x" /><xsl:text>
</xsl:text>
</xsl:template><xsl:template name="findCount"> <xsl:param name="prev-p" /> <xsl:param name="result" /> <xsl:choose>
<xsl:when test="$prev-p/self::p and not($prev-p/component)">
<xsl:call-template name="findCount">
<xsl:with-param name="prev-p"
select="$prev-p/preceding-sibling::p[1]" />
<xsl:with-param name="result" select="$result + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$result" />
</xsl:otherwise>
</xsl:choose>
</xsl:template></xsl:stylesheet> This when applied to the given XML, produces the desired output: p node value Count text 0 text2 1 text3 0 text4 1 text5 2 text6 3 text7 0 text8 1 text9 2 PS: I have used a recursive named template, to walk through "p" elements along preceding-sibling axis. On 5/27/07, Jeremy Freedman <jeremy.freedman@xxxxxxxxx> wrote: Hi all, -- Regards, Mukul Gandhi
|

Cart



