A
adi
hello all,
seems like a simple issue, but having tried several approaches with
no success I am posting this question,
I have a XML in one format, I want to now convert into another XML
format using XSLT.
FirstType.XML: (In this XML the States sub elements appear within USA
element)
------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<Country>
<USA>
<State>
<City1>6000</City1>
<City2>100</City2>
<City3> </City3>
</State>
<State>
<City1>1000</City1>
<City2>10</City2>
<City3>2</City3>
</State>
</USA>
</Country>
</ROOT>
------------------------------------------------
DestinationXML: (I want the above XML to appear this way, note the
element <Type> is something I want to add - and is not in the originial
XML)
------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Region>
<Area>
<Type> Original </Type>
<City1>6000</City1>
<City2>100</City2>
</Area>
<Area>
<Type> Original </Type>
<City1>1000</City1>
<City2>10</City2>
</Area>
</Region>
------------------------------------------------
My XSLT (Obviously broken
------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Region>
<Area>
<xsl:apply-templates select="/"> <xsl:sort
select="ROOT/Country/USA/State/City1"/>
<xsl:sort select="ROOT/Country/USA/State/City2"/>
</xsl:apply-templates>
</Area>
</Region>
</xsl:template>
<xsl:template match="USA">
<xsl:for-each select="ROOT/Country/USA/State">
<xsl:attribute name="Type"> <xsl:text>1</xsl:text>
</xsl:attribute>
<xsl:attribute name="City1"> <xsl:value-of select="City1"/>
</xsl:attribute>
<xsl:attribute name="City2"> <xsl:value-of select="City2"/>
</xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------
I am using .NET classes to do the transformation. Please advice on what
I can do it fix this.
thanks for all help.
adi
seems like a simple issue, but having tried several approaches with
no success I am posting this question,
I have a XML in one format, I want to now convert into another XML
format using XSLT.
FirstType.XML: (In this XML the States sub elements appear within USA
element)
------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<Country>
<USA>
<State>
<City1>6000</City1>
<City2>100</City2>
<City3> </City3>
</State>
<State>
<City1>1000</City1>
<City2>10</City2>
<City3>2</City3>
</State>
</USA>
</Country>
</ROOT>
------------------------------------------------
DestinationXML: (I want the above XML to appear this way, note the
element <Type> is something I want to add - and is not in the originial
XML)
------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Region>
<Area>
<Type> Original </Type>
<City1>6000</City1>
<City2>100</City2>
</Area>
<Area>
<Type> Original </Type>
<City1>1000</City1>
<City2>10</City2>
</Area>
</Region>
------------------------------------------------
My XSLT (Obviously broken
------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Region>
<Area>
<xsl:apply-templates select="/"> <xsl:sort
select="ROOT/Country/USA/State/City1"/>
<xsl:sort select="ROOT/Country/USA/State/City2"/>
</xsl:apply-templates>
</Area>
</Region>
</xsl:template>
<xsl:template match="USA">
<xsl:for-each select="ROOT/Country/USA/State">
<xsl:attribute name="Type"> <xsl:text>1</xsl:text>
</xsl:attribute>
<xsl:attribute name="City1"> <xsl:value-of select="City1"/>
</xsl:attribute>
<xsl:attribute name="City2"> <xsl:value-of select="City2"/>
</xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------
I am using .NET classes to do the transformation. Please advice on what
I can do it fix this.
thanks for all help.
adi