I am trying to add an attribute to my xml document but when I try to copy
the existing elements and it's attributes it doesn't copy the attributes.
I know in the specification it says it will not copy the attributes. Does
anyone know of am easy solution to my problem.
example xml file
<customer>
<input dataFld="blue"/>
<input dataFld="red"/>
<customer>
What I want my file to look like when it's done.
<customer>
<input dataFld="blue" label="My Favorite" format="lowerCase"/>
<input dataFld="red" label="MyLeastFavorite"/>
<customer>
This is my output that adds the attribute I want but keep the dataFld
attribute.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc-file"/>
<xsl:template match="/">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="customer">
<xsl:copy>
<xsl:for-each select="*">
<xsl:value-of select="."/>
<xsl:copy>
<xsl:variable name="myKey" select="./@dataFld"/>
<xsl:variable name="currentProperty"
select="document($doc-file)/locale/*[name()=$myKey]"/>
<xsl:if test="$currentProperty">
<xsl:attribute name="{$currentProperty/@type}">
<xsl:value-of select="$currentProperty"/>
</xsl:attribute>
</xsl:if>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Thanks!
Laura L. Menke
IBMUSM07(menkell)
Phone 507-253-8901 Tie 5535907
menkell@xxxxxxxxxx
When facing a difficult task, act as though it is impossible to fail. If
you're going after Moby Dick, take along the
tartar sauce.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list