我對XSLT相當陌生,並且已經瀏覽了關於該主題的多篇文章,但似乎無法得到我需要做的最後一件事。我試圖從我已有的節點數據中出現的已知數據串中刪除條目。我已經將一個適用於單節點值但不是多值的解決方案拼湊在一起。如何根據多個節點值的搜索刪除多個數字?
,這裏是我的xml
<root>
<item>2</item>
<item>9</item>
<item>5</item>
</root>
這裏是我的代碼,對於一個節點值的工作原理:
<xsl:template match="item">
<xsl:copy>
<xsl:call-template name="replaceChars">
<xsl:with-param name="original" select="string('1 2 3 4 5 6 7 8 9 10')"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="replaceChars">
<xsl:param name="original"/>
<xsl:choose>
<xsl:when test="contains($original, current())">
<xsl:value-of select="substring-before($original, current())"/>
<xsl:variable name="after" select="substring-after($original, current())"/>
<xsl:variable name="char" select="substring-before($after, current())"/>
<xsl:value-of select="concat($char, $after)"/>
<xsl:call-template name="replaceChars">
<xsl:with-param name="original" select="substring-after($after, current())"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$original"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我最新的測試我試圖用這個:
<xsl:template match="item">
<xsl:copy>
<xsl:call-template name="replaceChars">
<xsl:with-param name="original" select="string('1 2 3 4 5 6 7 8 9 10')"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="replaceChars">
<xsl:param name="original"/>
<xsl:choose>
<xsl:when test="contains($original, current())">
<xsl:variable name="before" select="substring-before($original, current())"/>
<xsl:variable name="after" select="substring-after($original, current())"/>
<xsl:variable name="char" select="substring-before($after, current())"/>
<xsl:variable name="new" select="concat($before, $after)"/>
<xsl:call-template name="replaceChars">
<xsl:with-param name="original" select="$new"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$original"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我連續得到在響應中迭代了幾次的值。我想我的輸出爲以下:
我已經搜索在此廣泛,你可以看到我的例子是基於改變的搜索場景。任何幫助,將不勝感激。
感謝您的詳細信息和教學我會檢討這 – user1672039