I have following source xml
<forms>
<x>
<y>
<x-component select="foobar" />
</y>
</x>
<component name="foobar">
<some>
<component>
<value>text</value>
</component>
</some>
</component>
</forms>
I’m trying to transform it to following:
<?xml version="1.0" encoding="UTF-8"?>
<forms>
<x>
<y>
<component name="foobar">
<some>
<component>
<value>text</value>
</component>
</some>
</component>
</y>
</x>
</forms>
My xsl file is
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="x-component">
<yoba>
<xsl:attribute name="z">
<xsl:value-of select="@select"/>
</xsl:attribute>
<xsl:apply-templates select="/forms/component[@name=@select]/*" />
</yoba>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>
How can I pass value of the select attribute of the current node for this line (instead of PLACEHOLDER):
<xsl:apply-templates select="/forms/component[@name=<PLACEHOLDER>]/*" />
Use
current()/@select. Or better define a key<xsl:key name="k1" match="component" use="@name"/>and the do<xsl:apply-templates select="key('k1', @select)"/>.