无法在以 xmlns 开头的属性中使用 AVT 检索值

Cannot retrieve value using AVT in attributes prefaced by xmlns

我有一个看起来像这样的 xslt 样式表。我需要使用参数设置属性值。我打算为此使用 AVT。但是我发现 AVT 没有被替换为以“xmlns”开头的属性。我已经在下面的 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>

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

XSLT 2.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"/>