在XSLT中使用模板构造变量,然后应用xpath

时间:2019-03-12 06:33:21

标签: xpath xslt-2.0

我正在使用以下xslt

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.test.com/services/test/test/v1">

    <xsl:output method="xml" encoding="UTF-8"
        omit-xml-declaration="yes" indent="yes" />
    <xsl:strip-space elements="*" />

    <xsl:template match="/">

            <xsl:variable name="mytree">
                <xsl:call-template name="myvariable">
                </xsl:call-template>
            </xsl:variable>

        <xsl:choose>    
            <xsl:when test="count($mytree/foos/foo) &gt; 1">
                <xsl:copy-of select="$mytree"/>
            </xsl:when>
            <xsl:otherwise>
                <error>test</error>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>

    <xsl:template name="myvariable">
        <foos>
            <foo>bar1</foo>
            <foo>bar2</foo>
            <foo>bar3</foo>
            <foo>bar4</foo>
        </foos>
    </xsl:template>   

</xsl:stylesheet>

当我在xslt上面使用时,它应该跟随输出

<foos xmlns="http://www.test.com/services/test/test/v1">
    <foo>bar1</foo>
    <foo>bar2</foo>
    <foo>bar3</foo>
    <foo>bar4</foo>
</foos>

但是是

<error xmlns="http://www.test.com/services/test/test/v1">test</error>

当我删除xmlns="http://www.test.com/services/test/test/v1"输出时是正确的。不知道发生了什么事?

0 个答案:

没有答案
相关问题