XML to XML Using XSLT without namespace -
i'm able convert 1 xml when input xml doesn't have namespace i'm not able desired output when input xml has namespace.
input.xml(w/o namespace)
<?xml version="1.0" encoding="utf-8"?> <addressbook> <address> <addressee>john smith</addressee> <streetaddress>250 18th ave se</streetaddress> <city>rochester</city> <state>mn</state> <postalcode>55902</postalcode> </address> <address> <addressee>yogesh</addressee> <streetaddress>saligramam</streetaddress> <city>chennai</city> <state>tamil nadu</state> <postalcode>600026</postalcode> </address> </addressbook>
xsl
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <xsl:element name="employeedetail"> <xsl:apply-templates select="addressbook/address"/> </xsl:element> </xsl:template> <xsl:template match="addressbook/address"> <xsl:element name="employee" > <xsl:value-of select="concat(city,'-',addressee,'-',postalcode)"/> </xsl:element> </xsl:template> </xsl:stylesheet>
output.xml(w/o namespace)
<?xml version="1.0" encoding="utf-8"?><employeedetail> <employee>rochester-john smith-55902</employee> <employee>chennai-yogesh-600026</employee> </employeedetail>
input xml (with namespace)
<?xml version="1.0" encoding="utf-8"?> <addressbook xlmns="http:\\abc.com\buspart"> <address> <addressee>john smith</addressee> <streetaddress>250 18th ave se</streetaddress> <city>rochester</city> <state>mn</state> <postalcode>55902</postalcode> </address> <address> <addressee>yogesh</addressee> <streetaddress>saligramam</streetaddress> <city>chennai</city> <state>tamil nadu</state> <postalcode>600026</postalcode> </address> </addressbook>
output.xml above input(with namespace)
<?xml version="1.0" encoding="utf-8"?></employeedetail>
how can retrieve result above input(which has namespace)?
the following xsl works:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:f="http:\\abc.com\buspart"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <xsl:element name="employeedetail"> <xsl:apply-templates select="/f:addressbook/f:address"/> </xsl:element> </xsl:template> <xsl:template match="/f:addressbook/f:address"> <xsl:element name="employee" > <xsl:value-of select="concat(f:city, '-', f:addressee, '-', f:postalcode)"/> </xsl:element> </xsl:template> </xsl:stylesheet>
this because adding namespace input xml can no longer refer xml element local name alone, must specify namespace uri portion of path (see http://en.wikipedia.org/wiki/xpath#syntax_and_semantics_.28xpath_1.0.29)
btw, have typo in input xml: xlmns should xmlns.
output:
<employeedetail> <employee>rochester-john smith-55902</employee> <employee>chennai-yogesh-600026</employee> </employeedetail>
Comments
Post a Comment