3
最初のXSLTを書き込もうとしています。属性ref
が "$ .root"で始まり、 ".newRoot"を挿入するすべてのbind
要素を見つける必要があります。特定の属性に一致するように管理していますが、更新された属性値をどのように出力するのかわかりません。特定の属性の値をXSLTで編集する
入力例の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>
ありがとうございます! ref属性が現在のノードの場合、なぜxsl:attribute要素に名前を付ける必要がありますか? –
@Björn好きな場合は、現在のノードの名前を文字どおりに指定する代わりに計算することができます。 ''。 –