使用xsl:number
:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="cell|option">
<xsl:call-template name="identity"/>
<xsl:variable name="vPosition">
<xsl:number count="cell|option" level="any" from="row" />
</xsl:variable>
<xsl:value-of select="$vPosition - 1"/>
</xsl:template>
</xsl:stylesheet>
使用此输入(更多row
s):
<table>
<row>
<cell>Phrase 1</cell> #0
<check shuffle="False">
<option key="1"/> #1
<option key="0"/> #2
<option key="0"/> #3
<option key="0"/> #4
<option key="0"/> #5
<option key="0"/> #6
</check>
<cell>Phrase 2</cell> #7
<cell>Phrase 3</cell> #8
<check shuffle="False">
<option key="1"/> #9
<option key="0"/> #10
<option key="0"/> #11
<option key="0"/> #12
<option key="0"/> #13
<option key="0"/> #14
</check>
</row>
<row>
<cell>Phrase 1</cell> #0
<check shuffle="False">
<option key="1"/> #1
<option key="0"/> #2
<option key="0"/> #3
</check>
<cell>Phrase 2</cell> #4
<check shuffle="False">
<option key="1"/> #5
<option key="0"/> #6
</check>
<cell>Phrase 3</cell> #7
</row>
</table>
输出:
<table>
<row>
<cell>Phrase 1</cell>0 #0
<check shuffle="False">
<option key="1"></option>1 #1
<option key="0"></option>2 #2
<option key="0"></option>3 #3
<option key="0"></option>4 #4
<option key="0"></option>5 #5
<option key="0"></option>6 #6
</check>
<cell>Phrase 2</cell>7 #7
<cell>Phrase 3</cell>8 #8
<check shuffle="False">
<option key="1"></option>9 #9
<option key="0"></option>10 #10
<option key="0"></option>11 #11
<option key="0"></option>12 #12
<option key="0"></option>13 #13
<option key="0"></option>14 #14
</check>
</row>
<row>
<cell>Phrase 1</cell>0 #0
<check shuffle="False">
<option key="1"></option>1 #1
<option key="0"></option>2 #2
<option key="0"></option>3 #3
</check>
<cell>Phrase 2</cell>4 #4
<check shuffle="False">
<option key="1"></option>5 #5
<option key="0"></option>6 #6
</check>
<cell>Phrase 3</cell>7 #7
</row>
</table>