Re: [xsl] Element name Change for a node

Subject: Re: [xsl] Element name Change for a node
From: Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx>
Date: Thu, 14 Sep 2006 11:29:19 -0700
Thanks Michael Kay for help.It is so simple to follow and helped me great indeed .
Regards.,
Senthil
On Sep 14, 2006, at 12:52 AM, Michael Kay wrote:


I would do this as:

 <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes" />

   <xsl:template match="*">
     <xsl:copy>
       <xsl:apply-templates />
     </xsl:copy>
   </xsl:template>

   <xsl:template match="address/*">
     <xsl:element name="US_{local-name()}">
       <xsl:apply-templates/>
     </xsl:element>
   </xsl:template>

</xsl:stylesheet>

 Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx]
Sent: 14 September 2006 05:20
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Element name Change for a node

Please try this stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes" />

  <xsl:template match="/address">
    <address>
      <xsl:apply-templates />
    </address>
  </xsl:template>

  <xsl:template match="*[../self::address]">
    <xsl:element name="{concat('US_', local-name())}">
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

This when applied to XML:

<address>
  <streetAddress>123 First Street</streetAddress>
  <city>Sometown</city>
  <state>CA</state>
  <zip>12345</zip>
  <province/>
  <country>USA</country>
</address>

Produces output:

<?xml version="1.0" encoding="UTF-8"?>
<address>
   <US_streetAddress>123 First Street</US_streetAddress>
   <US_city>Sometown</US_city>
   <US_state>CA</US_state>
   <US_zip>12345</US_zip>
   <US_province/>
   <US_country>USA</US_country>
</address>


On 9/14/06, Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx> wrote:

Hi All,


I have the following structure in my XML and I want to
transform this
all "address" node content to prefix with "US".
Please let me how to create the XSL template for the given input.

Input
  <address>
   <streetAddress>123 First Street</streetAddress>
     <city>Sometown</city>
     <state>CA</state>
     <zip>12345</zip>
     <province />
     <country>USA</country>
  </address>

output
  <address>
   <US_streetAddress>123 First Street</US_streetAddress>
     <US_city>Sometown</US_city>
     <US_state>CA<US_/state>
     <US_zip>12345</US_zip>
     <US_province />
     <US_country>USA</US_country>
  </address>

I do not know how to create the XSL for it to transform.

Thanks for your help.


Regards, Senthil


--
Regards,
Mukul Gandhi

http://gandhimukul.tripod.com

Current Thread