[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: one XML Format to other XML Format using XSLT


xslt date format
In a message dated 14/06/2003 09:32:45 GMT Daylight Time, xmlbar@h... writes:

I am new to XML and in process of converting one XML format to another XML
format using XSLT. My conversion looks something as below (transforming
A.xml to B.xml)

A.xml

<Employee SBU=23>
   <Name> A </Name>
   <ID> 1 </ID>
   <Team> XYZ </Team
</Employee>

B.xml

<Employee ID="1" Team="XYZ">
   <Name> A </Name>
</Employee>

Need help to build an xsl file for this conversion ?

Thanks
Bhargav


Bhargav,

You have a couple of errors in A.xml.

Assuming those are corrected then the following stylesheet gives you the output that you described.

<?xml version='1.0'?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/">
<xsl:apply-templates select="Employee" />
</xsl:template>

<xsl:template match="Employee">
<xsl:copy>
  <xsl:attribute name="ID">
   <xsl:value-of select="normalize-space(ID)" />
  </xsl:attribute>
  <xsl:attribute name="Team">
   <xsl:value-of select="normalize-space(Team)" />
  </xsl:attribute>
  <xsl:copy-of select="Name" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

If you didn't intend the spaces in the value of the <Team> and <ID> elements you won't need the normalize-space() function in the stylesheet.

XSLT questions are normally best asked on the XSL-List.

See http://www.mulberrytech.com/xsl/xsl-list/index.html

Andrew Watt

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.