Athapali
Athapali

Reputation: 1089

for each odd numbered row xsl

How do I do for-each for all the odd numbered rows? XML looks like this:

<dsQueryResponse ViewStyleID="" BaseViewID="" TemplateType="" RowLimit="">
  <Rows>
    <Row title="A"/>
    <Row title="B"/>
    <Row title="C"/>
    <Row title="D"/>
    <Row title="E"/>
    <Row title="F"/>
</Rows>
</dsQueryResponse>

This doesn't work:

 <xsl:for-each  select="../Row[position() mod 2 =1]" />

Upvotes: 2

Views: 1316

Answers (1)

Francis Avila
Francis Avila

Reputation: 31631

Your basic technique (using position() mod 2) is correct as demonstrated by the complete stylesheet below:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/dsQueryResponse/Rows">
        <xsl:for-each  select="Row[position() mod 2 = 1]">
            <xsl:value-of select="./@title"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Your problem is probably with the particular context you are in not being what you expect; but since you don't show the rest of your code we have no way of helping you.

Upvotes: 3

Related Questions