use of <xsl:copy>

Subject: use of <xsl:copy>
From: menkell@xxxxxxxxxx
Date: Mon, 7 Feb 2000 18:35:36 -0600
I am pretty new to xsl and am not sure of the right way to use <xsl:copy>.
If i use it a lot is there going to be significant performance problems?
Is there a better way to do what I am trying to do?     Basically I have a
xml document and I want to insert a <label> element that I pull from a
different xml document into my original document based on a key.    Here is
my current xsl document, my two input xmls, and my final output.    I would
just like comment on if I am doing this the right way or if there is a
better way.

MY XSL
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="object">
     <xsl:copy>
     <xsl:for-each select="property">
        <xsl:copy>
          <xsl:variable name="myKey" select="key"/>
          <xsl:if test="document('en_US.xml')/locale/*[name()=$myKey]">
               <xsl:element name="label">
                   <xsl:value-of
select="document('en_US.xml')/locale/*[name()=$myKey]"/>
               </xsl:element>
          </xsl:if>
          <xsl:copy-of select="./*"/>
         </xsl:copy>
     </xsl:for-each>
     </xsl:copy>
</xsl:template>
</xsl:stylesheet>



MY currencyGen.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl"?>
<object>
   <property>
     <key>currencyCode</key>
     <value>USD</value>
    </property>
   <property>
     <key>fraction</key>
     <value>cent</value>
    </property>
   <property>
     <key>exchange</key>
     <value>1.5</value>
    </property>
</object>



This is my en_us.xml:
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl"?>
<locale>
     <currencyCode>Currency Code</currencyCode>
     <fraction>Fraction</fraction>
</locale>



My output document:
<?xml version="1.0" encoding="UTF-8"?>
<object>
   <property>
     <label>Currency Code</label>
     <key>currencyCode</key>
     <value>USD</value>
   </property>
   <property>
     <label>Fraction</label>
     <key>fraction</key>
     <value>cent</value>
    </property>
   <property>
          <key>exchange</key>
     <value>1.5</value>
    </property>
</object>




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


Current Thread