【发布时间】:2014-08-25 14:18:09
【问题描述】:
假设我有两种类型的 XML 元素,其文本内容可以是“真”或“假”:
<elementA>true</elementA>,
<elementB>false</elementB>
我想创建一个新元素
<result>$content</result>
其中变量 $content 基于两个输入元素值可以有 4 种类型的值:
真的,真的 -> 一个
真,假-> B
假,真 -> C
假,假-> D
我试图用 xsl:function 解决这个问题,但不知道如何同时选择这两个元素(我对 xslt 几乎没有经验)。 是否可以进行这种转换?
编辑
我正在尝试您的第二种解决方案,但是我的主要问题来源是我不知道如何将变量传递给我的函数。目前我有以下代码:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:function name="transform">
<xsl:param name="p1"></xsl:param>
<xsl:param name="p2"></xsl:param>
<xsl:choose>
<xsl:when test="$p1='true' and $p2='true'">
<orderingType>RND</orderingType>
</xsl:when>
<xsl:when test="$p1='true' and $p2='false'">
<orderingType>FIX</orderingType>
</xsl:when>
<xsl:when test="$p1='false' and $p2='false'">
<orderingType>PREF</orderingType>
</xsl:when>
</xsl:choose>
</xsl:function>
<xsl:template match="//action/*">
<xsl:variable name="var1" select="shuffle"></xsl:variable>
<xsl:variable name="var2" select="limitOn"></xsl:variable>
</xsl:template>
【问题讨论】: