与嵌套if条件的XSL串联

时间:2015-10-22 06:53:43

标签: xslt

我有以下xml

<string1>Y</string1>
<string2>aaabbbcccddd</string2>
<string3>I have to concatentate this</string3>

我必须将这三个元素连接起来如下。 如果string1存在标志Y,则硬编码'Flag Y exists'+ string2(如果存在)+ string3。 请帮我解决xsl短语 提前谢谢

1 个答案:

答案 0 :(得分:0)

我认为没有必要在这里筑巢:

<xsl:if test="string1='Y'">
    <xsl:value-of select="concat('Flag Y exists', string2, string3)"/>
</xsl:if>
  

这三个正在工作,但现在在xml我有额外的   <string4>string4</string4>也应该添加到   连接,但只有它不是空的。如果是这种情况   匹配然后硬编码'string4不为空'应添加

     

这里我需要嵌套......

是的,但这很简单:

<xsl:if test="string1='Y'">
    <xsl:value-of select="concat('Flag Y exists', string2, string3)"/>
    <xsl:if test="string(string4)">string4 is not empty</xsl:if>
</xsl:if>
相关问题