有没有什么办法可以在XSLT不存在时使用XSLT生成唯一的ID(顺序很好)?我有以下几点:任何方式在XSLT中生成计数器值?
<xsl:template match="Foo">
<xsl:variable name="varName">
<xsl:call-template name="getVarName">
<xsl:with-param name="name" select="@name"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$varName"/> = <xsl:value-of select="@value"/>
</xsl:template>
<xsl:template name="getVarName">
<xsl:param name="name" select="''"/>
<xsl:choose>
<xsl:when test="string-length($name) > 0">
<xsl:value-of select="$name"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>someUniqueID</xsl:text> <!-- Stuck here -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
随着类似的输入:
<Foo name="item1" value="100"/>
<Foo name="item2" value="200"/>
<Foo value="300"/>
我希望能够让我最终分配一个唯一的值:
item1 = 100
item2 = 200
unnamed1 = 300
这工作很好,谢谢! – Jon 2010-02-23 19:50:08