Loops 如何在XSLT1.0中获取具有唯一数字的数字?
我有下面的变量Loops 如何在XSLT1.0中获取具有唯一数字的数字?,loops,xslt,xslt-1.0,unique,number-formatting,Loops,Xslt,Xslt 1.0,Unique,Number Formatting,我有下面的变量 <xsl:variable name="number" select="56568"/> 所需产出:568 我需要得到一个只包含数字中唯一数字的输出 你知道如何在XSLT1.0中实现这一点吗 谢谢我认为没有一种简单的方法可以做到这一点,除非您的处理器支持一些扩展功能。如果没有它,则必须使用递归命名模板: <xsl:template name="distinct-characters"> <xsl:param name="input"/&
<xsl:variable name="number" select="56568"/>
所需产出:568
我需要得到一个只包含数字中唯一数字的输出
你知道如何在XSLT1.0中实现这一点吗
谢谢我认为没有一种简单的方法可以做到这一点,除非您的处理器支持一些扩展功能。如果没有它,则必须使用递归命名模板:
<xsl:template name="distinct-characters">
<xsl:param name="input"/>
<xsl:param name="output"/>
<xsl:choose>
<xsl:when test="not($input)">
<xsl:value-of select="$output"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="char" select="substring($input, 1, 1)" />
<!-- recursive call -->
<xsl:call-template name="distinct-characters">
<xsl:with-param name="input" select="substring($input, 2)"/>
<xsl:with-param name="output">
<xsl:value-of select="$output"/>
<xsl:if test="not(contains($output, $char))">
<xsl:value-of select="$char"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
呼叫示例:
<output>
<xsl:call-template name="distinct-characters">
<xsl:with-param name="input" select="56568"/>
</xsl:call-template>
</output>
结果:
<output>568</output>
568
演示:哪个XSLT1.0处理器?如果您可以访问一些扩展函数,这可能会更容易。在XSLT2.0中,您当然可以执行
代码点到字符串(不同的值(字符串到代码点($In)))