我想写我的第一个XSLT。它需要查找所有属性ref
以 "$.root" 开头的所有 bind
元素,然后插入 ".newRoot"。我已经成功匹配了特定的属性,但我不知道如何将其打印为更新后的属性值。
输入示例XML:
<?xml version="1.0" encoding="utf-8" ?>
<top>
<products>
<product>
<bind ref="$.root.other0"/>
</product>
<product>
<bind ref="$.other1"/>
</product>
<product>
<bind ref="$.other2"/>
</product>
<product>
<bind ref="$.root.other3"/>
</product>
</products>
</top>
到目前为止,我的XSL如下:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bind[starts-with(@ref,'$.root')]/@ref">
<xsl:attribute name="ref">$.newRoot<xsl:value-of select="bind/@ref" /></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
我希望从输入中产生的XML:
<?xml version="1.0" encoding="utf-8" ?>
<top>
<products>
<product>
<bind ref="$.newRoot.root.other0"/>
</product>
<product>
<bind ref="$.other1"/>
</product>
<product>
<bind ref="$.other2"/>
</product>
<product>
<bind ref="$.newRoot.root.other3"/>
</product>
</products>
</top>
<xsl:attribute name="{name()}">
。 - michael.hor257k