I'm trying to write my first XSLT. It needs to find all bind elements where the attribute ref begins with "$.root" and then insert ".newRoot". I have managed to match for the specific attribute, but I don't understand how I can get it to print an updated attribute value.
Input example 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>
My XSL so far:
<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>
The XML I would like to produce from the input:
<?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>