Joe Kesselman wrote:
You could then consider removing the predicates from the templates for
position and client.
I am still having trouble. I changed the xslt to this. I think it
should produce an exact replica of the original XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<pallet>
<xsl:apply-templates select="pallet/position"/>
</pallet>
</xsl:template>
<xsl:template match="pallet">
<!-- BEGIN YOUR CHANGE -->
<xsl:apply-templates select="position"/>
<xsl:apply-templates select="position/client"/>
<!-- END YOUR CHANGE -->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="position">
<position>
<xsl:attribute name="row">
<xsl:value-of select="@row"/>
</xsl:attribute>
<xsl:attribute name="bay">
<xsl:value-of select="@bay"/>
</xsl:attribute>
<xsl:attribute name="level">
<xsl:value-of select="@level"/>
</xsl:attribute>
</position>
<xsl:apply-templates/>
</xsl:template>
<!-- BEGIN YOUR CHANGE -->
<xsl:template match="client[../position]">
<client>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<!-- possible apply-templates here? -->
</client>
</xsl:template>
<!-- END YOUR CHANGE -->
</xsl:stylesheet>
And the result is:
<?xml version="1.0" encoding="UTF-16"?>
<pallet>
<position row="0" bay="0" level="A" />
<position row="1" bay="1" level="B" />
<position row="1" bay="1" level="C" />
</pallet>
Instead of
<?xml version="1.0" encoding="UTF-8"?>
<pallet>
<position row="0" bay="0" level="A">
<client id="ABC"></client>
</position>
<position row="1" bay="1" level="B">
<client id="DEF"></client>
</position>
<position row="1" bay="1" level="C">
<client id="GHI"></client>
</position>
</pallet>