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