i am trying to transform an xml into a new one where the only one of the elements transforms it self into an attribute and keep the rest of the document tree in the same way... there is the xml.doc
<?xml version="1.0" encoding="UTF-8"?> <cities> <city> <cityID>c1</cityID> <cityName>Atlanta</cityName> <cityCountry>USA</cityCountry> <cityPop>4000000</cityPop> <cityHostYr>1996</cityHostYr> </city> <city> <cityID>c2</cityID> <cityName>Sydney</cityName> <cityCountry>Australia</cityCountry> <cityPop>4000000</cityPop> <cityHostYr>2000</cityHostYr> <cityPreviousHost>c1</cityPreviousHost > </city> <city> <cityID>c3</cityID> <cityName>Athens</cityName> <cityCountry>Greece</cityCountry> <cityPop>3500000</cityPop> <cityHostYr>2004</cityHostYr> <cityPreviousHost>c2</cityPreviousHost > </city> </cities> i am trying to get the "cityID" element into an attribute to "city" and keep the rest. there is my .xsl so far. Unfortunately seems to loose the rest of the elements: <?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="/"> <cities> <xsl:apply-templates/> </cities> </xsl:template> <xsl:template match="city"> <xsl:element name="city" use-attribute-sets="NameAttributes"/> </xsl:template> <xsl:attribute-set name="NameAttributes"> <xsl:attribute name="cityID"> <xsl:value-of select="cityID"/> </xsl:attribute> </xsl:attribute-set> <xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet> will be happy to see some suggestions. 10x in advance
No comments:
Post a Comment