0
我是xslt的新手,請原諒我的任何錯誤。
在xsl程序中,我得到了一個名爲「foo:vars」的變量值列表,其中包含一個顏色值列表。
有聲明爲matchWith一個變量,它可以包含任何值(不一定存在於福爾:VAR列表)
XSLT:如何模仿xslt:foreach中的標誌或break語句迭代變量列表
程序應該輸出爲:
- 如果變量matchWith包含在列表「foo:vars」中存在的值,則值應該出現在具有匹配值的標籤
<color_found>
中。 - 一樣,存在於可變matchWith值應該出現在命名爲
<color_not_found>
下面的另一個標籤是程序,即能給出案例1正確的輸出,但我失敗狀況的任何標誌的情況下, 2.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:foo="http://foo.com" exclude-result-prefixes="foo">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<foo:vars>
<foo:var name="a1">Yellow</foo:var>
<foo:var name="b1">red</foo:var>
<foo:var name="c1">green</foo:var>
<foo:var name="d1">blue</foo:var>
</foo:vars>
<xsl:variable name="matchWith">Yellow</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="document('')/xsl:stylesheet/foo:vars/foo:var">
<xsl:variable name="temp">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$temp=$matchWith">
<color_found>
<xsl:value-of select="$matchWith"/>
</color_found>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
感謝它爲場景中的答案。有沒有一種方法可以讓我有兩個塊(可以是,如果是其他類型的話),如果匹配找到/未找到,我需要執行不同的語句集。 if(matchWith presents){some code to execute} else {some other code to be executed} – Harish
@Harish是的,您可以使用一些代碼來執行一些其他要執行的代碼 xsl:otherwise> ' –
JLRishe
謝謝,這是一個很大的幫助。 – Harish