Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在xmlns前面的属性中使用AVT检索值_Xml_Xslt_Xslt 2.0 - Fatal编程技术网

无法在xmlns前面的属性中使用AVT检索值

无法在xmlns前面的属性中使用AVT检索值,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我有一个xslt样式表,如下所示。我需要使用参数设置属性值。我打算为此使用AVT。但是,我发现在以“xmlns”开头的属性中并没有替换AVT。我已经在下面的xslt中指出了这些问题。欢迎提出任何建议 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclud

我有一个xslt样式表,如下所示。我需要使用参数设置属性值。我打算为此使用AVT。但是,我发现在以“xmlns”开头的属性中并没有替换AVT。我已经在下面的xslt中指出了这些问题。欢迎提出任何建议

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs xsl" version="2.0">
    <xsl:output omit-xml-declaration="no" indent="yes" />
    <xsl:variable name="type" select="'mytype'"/>
    <xsl:template match="Root"> 

        <xsl:comment select="$type" /> <!-- Getting output here -->

        <out xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:a="{$type}" <!-- Not getting output here -->
            b="{$type}">      <!-- Getting output here -->

            <nestOut xmlns:nc="{$type}" <!-- Not getting output here -->
                     xsi:na="{$type}"   <!-- Getting output here -->
                     nb="{$type}">Test  <!-- Getting output here -->
            </nestOut>
        </out>
    </xsl:template>
</xsl:stylesheet>

nb=“{$type}”>测试

命名空间声明不是属性。您可以使用该指令生成具有已计算名称空间URI的名称空间节点。考虑这个简化的例子:

XSLT2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="my-URI" select="'http:example.com/mynamespace'"/>

<xsl:template match="/">
    <out>
        <xsl:namespace name="a">
            <xsl:value-of select="$my-URI"/>
        </xsl:namespace>
    </out>
</xsl:template>

</xsl:stylesheet>

结果

<?xml version="1.0" encoding="UTF-8"?>
<out xmlns:a="http:example.com/mynamespace"/>


谢谢!我能让它工作。出现的一个问题是,在我上面的示例中,它如何适用于“xsi:na”属性?因为这是一个属性,而不是名称空间声明。名称空间声明看起来像属性,但实际上不是。