Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone got an alternative to position() in WD-xsl?

Status
Not open for further replies.

gdrenfrew

Programmer
Joined
Aug 1, 2002
Messages
227
Location
GB
Hi there,

I want to be able to count the position of each record in an xsl:for-each loop. Unfortunately, the function position() is not available in the WD-XSL stylesheet which I have to use.

Is there an alternative method for finding the position of each record?

Thanks,
Graeme
 
I dont know WD-XSL, but in xsl you can use a named template that calls itself recursively.
Code:
<xsl:template match="List">
  <xsl:call-template name="ParseListNode">
    <xsl:with-param name="number" select="1" />
    <xsl:with-param name="node" select="Node" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="ParseListNode">
  <xsl:param name="number" />
  <xsl:param name="node" />

  <xsl:if test="$node">
    <!-- if $node is empty we're at the end of the list -->
    <xsl:value-of select="$number" />
    <xsl:value-of select="$node/childnode" />
    <!-- or whatever you want to display -->
    <xsl:call-template name="ParseListNode">
      <xsl:with-param name="number" select="$number + 1" />
      <xsl:with-param name="node" select="$node/following-sibling::Node" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top