(XSLT 2.0) for-each 变量名称中的动态数字
(XSLT 2.0) Dynamic number in name of variable in for-each
我有这些变量:
<xsl:variable name="dystrybutor1" select="count(//gra[dystrybutor='Atari'])"/>
<xsl:variable name="dystrybutor2" select="count(//gra[dystrybutor='CD Projekt'])"/>
<xsl:variable name="dystrybutor3" select="count(//gra[dystrybutor='Cenega'])"/>
<xsl:variable name="dystrybutor4" select="count(//gra[dystrybutor='Double Fine'])"/>
<xsl:variable name="dystrybutor5" select="count(//gra[dystrybutor='Electronic Arts'])"/>
<xsl:variable name="dystrybutor6" select="count(//gra[dystrybutor='LEM'])"/>
<xsl:variable name="dystrybutor7" select="count(//gra[dystrybutor='Rockstar Games'])"/>
这些说明:
<text x="85" y="{(($max)-(80*$dystrybutor1))+5}"><xsl:value-of select="$dystrybutor1"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor2))+5}"><xsl:value-of select="$dystrybutor2"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor3))+5}"><xsl:value-of select="$dystrybutor3"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor4))+5}"><xsl:value-of select="$dystrybutor4"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor5))+5}"><xsl:value-of select="$dystrybutor5"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor6))+5}"><xsl:value-of select="$dystrybutor6"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor7))+5}"><xsl:value-of select="$dystrybutor7"/></text>
是否可以让 for-each 在变量名中增加数字?
类似于:
<xsl:for-each select="1 to 7"><text x="85" y="{(($max)-(80*$dystrybutor{NUMBER}))+5}"><xsl:value-of select="$dystrybutor{NUMBER}"/>[some instruction to increment NUMBER]</text></xsl:for-each>
您可以重新组织代码以声明一个具有这些值序列的变量
<xsl:variable name="distributors"
select="count(//gra[dystrybutor='Atari']),
count(//gra[dystrybutor='CD Projekt']),
count(//gra[dystrybutor='Cenega']),
count(//gra[dystrybutor='Double Fine']),
count(//gra[dystrybutor='Electronic Arts']),
count(//gra[dystrybutor='LEM']),
count(//gra[dystrybutor='Rockstar Games'])"/>
然后处理这些值
<xsl:for-each select="$distributors">
<text x="85" y="{(($max)-(80 * .))+5}">
<xsl:value-of select="."/>
</text>
</xsl:for-each>
我有这些变量:
<xsl:variable name="dystrybutor1" select="count(//gra[dystrybutor='Atari'])"/>
<xsl:variable name="dystrybutor2" select="count(//gra[dystrybutor='CD Projekt'])"/>
<xsl:variable name="dystrybutor3" select="count(//gra[dystrybutor='Cenega'])"/>
<xsl:variable name="dystrybutor4" select="count(//gra[dystrybutor='Double Fine'])"/>
<xsl:variable name="dystrybutor5" select="count(//gra[dystrybutor='Electronic Arts'])"/>
<xsl:variable name="dystrybutor6" select="count(//gra[dystrybutor='LEM'])"/>
<xsl:variable name="dystrybutor7" select="count(//gra[dystrybutor='Rockstar Games'])"/>
这些说明:
<text x="85" y="{(($max)-(80*$dystrybutor1))+5}"><xsl:value-of select="$dystrybutor1"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor2))+5}"><xsl:value-of select="$dystrybutor2"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor3))+5}"><xsl:value-of select="$dystrybutor3"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor4))+5}"><xsl:value-of select="$dystrybutor4"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor5))+5}"><xsl:value-of select="$dystrybutor5"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor6))+5}"><xsl:value-of select="$dystrybutor6"/></text>
<text x="85" y="{(($max)-(80*$dystrybutor7))+5}"><xsl:value-of select="$dystrybutor7"/></text>
是否可以让 for-each 在变量名中增加数字? 类似于:
<xsl:for-each select="1 to 7"><text x="85" y="{(($max)-(80*$dystrybutor{NUMBER}))+5}"><xsl:value-of select="$dystrybutor{NUMBER}"/>[some instruction to increment NUMBER]</text></xsl:for-each>
您可以重新组织代码以声明一个具有这些值序列的变量
<xsl:variable name="distributors"
select="count(//gra[dystrybutor='Atari']),
count(//gra[dystrybutor='CD Projekt']),
count(//gra[dystrybutor='Cenega']),
count(//gra[dystrybutor='Double Fine']),
count(//gra[dystrybutor='Electronic Arts']),
count(//gra[dystrybutor='LEM']),
count(//gra[dystrybutor='Rockstar Games'])"/>
然后处理这些值
<xsl:for-each select="$distributors">
<text x="85" y="{(($max)-(80 * .))+5}">
<xsl:value-of select="."/>
</text>
</xsl:for-each>