如何在xslt 1中创建变量

时间:2017-05-09 16:36:35

标签: xml xslt xslt-1.0

你能告诉我如何在变量中组合xml吗?

输入xml

<video>
    <a>
        <c>
            <d>hello</d>
            <d>jjjj</d>
        </c>
    </a>
    <b>
        <c>
            <d>test</d>
            <d>sss</d>
        </c>
    </b>
</video>

代码

    <xsl:template match="video">
        <xsl:variable name="videoList">
            <video>
                <xsl:copy-of select="//./a/c"></xsl:copy-of>
                <xsl:copy-of select="//./b/c"></xsl:copy-of>

            </video>
        </xsl:variable>
        <xsl:copy-of select="$videoList"/>
  </xsl:template>

</xsl:stylesheet>

输出

<video>
    <c>
        <d>hello</d>
        <d>jjjj</d>
    </c>
    <c>
        <d>test</d>
        <d>sss</d>
    </c>
</video>

预期输出

<video>
    <c>
        <d>hello</d>
        <d>jjjj</d>

        <d>test</d>
        <d>sss</d>
    </c>

</video>

2 个答案:

答案 0 :(得分:1)

这个例子太抽象了,无法确定你所追求的是什么。获得结果的一种方法是将变量定义为:

<xsl:variable name="videoList">
        <video>
            <c>
                <xsl:copy-of select="a/c/d | b/c/d"/>
            </c>
        </video>
</xsl:variable>

答案 1 :(得分:1)

是什么让你认为你需要一个变量?你可以这样做:

<xsl:template match="video">
   <video>
     <c>
        <xsl:copy-of select=".//d"/>
     </c>
  </video>
</xsl:template>