2017-07-13 42 views
0

我有下面的變量。需要如何在XSLT 1.0中獲取唯一數字的數字?

<xsl:variable name="number" select="56568"/> 

輸出:568

我需要得到它包含的數量只有唯一數字的輸出。

任何想法如何在XSLT 1.0中實現這一點?

感謝

+0

哪XSLT 1.0處理器?如果您可以訪問某些擴展功能,這可能會更容易。 –

+0

在XSLT 2.0中當然可以使用'codepoints-to-string(distinct-values(string-to-codepoints($ in)))' –

回答

0

我不認爲有一個簡單的方法來做到這一點 - 除非您的處理器支持一些擴展功能。沒有它,你將不得不使用遞歸命名的模板:

<output> 
    <xsl:call-template name="distinct-characters"> 
     <xsl:with-param name="input" select="56568"/> 
    </xsl:call-template> 
</output> 

結果:

<output>568</output> 

演示:

<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> 

調用示例http://xsltransform.net/a9Gix1

+0

謝謝你的回答。 –