<root>
<tagA>foo</tagA>
<tagB id1="XXX" id2=YYY">boo</tagB>
<tagC ref="YYY">pie</tagC>
<tagD>bar</tagD>
</root>
TIA,
David
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
http://JavaScript.FAQTs.com/
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect">
<xsl:template match="@* | node()">
<redirect:write file="transformed.xml">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</redirect:write>
</xsl:template>
TIA!
David
That template is generating a file (with the same noame over and over
again) for every element, in the case of attributes it tries to copy the
attribute on its own to a new file but without an element to hold it,
that can't work.
If you just want to redirect the result of an identity transform then
you don't want a new file on every element, just the root:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<redirect:write file="transformed.xml">
<xsl:apply-templates/>
</redirect:write>
</xsl:template>
David
So, now that I'm successfully creating all the tags, how do I change
the values of the ref attribute in just the tagC elements?
Thanks again!
David
As suggested earlier:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<redirect:write file="transformed.xml">
<xsl:apply-templates/>
</redirect:write>
</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>
--
Martin Honnen
http://JavaScript.FAQTs.com/
Thanks again,
David