I have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Set>
<Tables>
<Table>
<Tablehead>
<C>Name</C>
<C>FirstName</C>
<C>Address</C>
<C>Zip</C>
<C>City</C>
<C>State</C>
</Tablehead>
<Rows>
<Person>
<C>Miller</C>
<C>John</C>
<C>Squires Circle</C>
<C>88034</C>
<C>Boulder</C>
<C>Colorado</C>
</Person>
</Rows>
</Table>
</Tables>
</Set>
</Data>
The element person can occur n-times. Now to properly work with that structure I have to rename the <C> tags first within <Person>.
I came up with this XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Rows">
<Rows>
<xsl:apply-templates select="Person"/>
</Rows>
</xsl:template>
<xsl:template match="Person">
<Person>
<xsl:apply-templates select="C"/>
</Person>
</xsl:template>
<xsl:template match="/Data/Set/Tables/Table/Rows/Person/C">
<xsl:variable name="nodePosition" select="position()" />
<xsl:value-of select="parent::*/parent::*/parent::*/Tablehead/C[$nodePosition]"/>
</xsl:template>
</xsl:stylesheet>
But the output is always this:
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Set>
<Tables>
<Table>
<Tablehead>
<C>Name</C>
<C>FirstName</C>
<C>Address</C>
<C>Zip</C>
<C>City</C>
<C>State</C>
</Tablehead>
<Rows>
<Person/>
</Rows>
</Table>
</Tables>
</Set>
</Data>
It looks fine but my <Person> element is always empty. What am I missing?
The following stylesheet
when applied to the input
outputs