David Schwartz wrote:
So, I've got some elements that refer to other elements based on one
id. Each of the referent elements actually have a second id (don't
ask) which I'd like to use instead (so I can drop the extra id). So,
based on the following data, I'd like to keep everything the same
except for having all tagC's referring to tagB's based on id1 instead
of id2. Again, everything else would be the same. I can figure out how
to make the switch in tagC's just fine but do I have to write a
template for every type of tag as well? Sure hope not!
<root>
<tagA>foo</tagA>
<tagB id1="XXX" id2=YYY">boo</tagB>
<tagC ref="YYY">pie</tagC>
<tagD>bar</tagD>
</root>
Using
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@id2"/>
<xsl:template match="tagC">
<xsl:copy>
<xsl:attribute name="ref">
<xsl:value-of select="../*[@id2 = current()/@ref]/@id1"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
should do, if I understand correctly what you want to achieve.
--
Martin Honnen
JavaScript.FAQTs.com/">http://JavaScript.FAQTs.com/
|