Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

xslt - How to increment a XSL integer variable

Updated

I have some huge data, which becomes a large table say table parent

each table parent's row will correspond to another table (code given below) say table child So when any particular column from the table parent row is clicked (hyperlinked) it goes to that part of table table child

so i need a counter to differentiate between each table child. Please help me figure out this problem. Thanks

<xsl:choose>
    <xsl:variable name="counter" as="xs:integer"/>
    $counter=0      <!--here i am assigning 0-->
    <xsl:when test="DBInfo/ORSDBInfo/ORSReposTableTypeInd1/ORSReposColumAllWithTableTypeInd1/@ColumnNm">
        <dd>
            <xsl:for-each select="DBInfo/ORSDBInfo/ORSReposTableTypeInd1">
                <div class="horz">
                <a name="_ORS$counter" href="#_top">ORSReposColumAllWithTableTypeInd1:<xsl:value-of select="$counter"/> </a>
                <table border="1">          <!--above I am using counter to print-->
                    <tbody>
                        <tr>
                            <th>Creator</th>
                            <th>LastUpdate</th>
                            <th>UpdatedBy</th>
                        </tr>
                <xsl:for-each select="ORSReposColumAllWithTableTypeInd1">
                    <tr>
                        <td><xsl:value-of select="@Creator"/></td>
                        <td><xsl:value-of select="@LastUpdate"/></td>
                        <td><xsl:value-of select="@UpdatedBy"/>
                    </tr>
                </xsl:for-each>
                    </tbody>
                </table>
            </div>
            $counter=$counter+1     <!--Counter is incremented-->
            <br/>
            </xsl:for-each>
        </dd>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
</xsl:choose>

More Updates

So after referring to Wilfred's answer I came up with

<a name="_ORS" href="#_top">ORSReposColumAllWithTableTypeInd1_<xsl:number value="position()" format="1" /></a>

but now how to use it inside <a name="_ORS" so that i get _ORS1, _ORS2, _ORS3 and so on...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use position(). Since you are incrementing this once per for-each why don't you simply use position()?

<a name="_ORS$counter" href="#_top">ORSReposColumAllWithTableTypeInd1:<xsl:value-of select="position()"/> </a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...