基于编码为树变量的字典来转换属性值

时间:2017-11-25 15:54:22

标签: xslt xpath xslt-2.0

我应该明白我要查看这些示例文件:

输入:

<root>
    <node type="A"/>
    <node type="B"/>
</root>

样式表:

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

    <xsl:variable name="fixes">
        <fix from="A" to="AA"/>
        <fix from="B" to="BB"/>
    </xsl:variable>

    <xsl:template match="@type[string()=$fixes/fix/@from]">
        <xsl:attribute name="type">
                <xsl:value-of select="$fixes/fix[@from=self::node()]/@to"/>
        </xsl:attribute>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

预期产出:

<root>
    <node type="AA"/>
    <node type="BB"/>
</root>

实际输出(使用saxon9he):

<root>
    <node type=""/>
    <node type=""/>
</root>

知道我做错了吗?

0 个答案:

没有答案