OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] one XML Format to other XML Format using XSLT

[ Lists Home | Date Index | Thread Index ]

In a message dated 14/06/2003 09:32:45 GMT Daylight Time, xmlbar@hotmail.com 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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS