XSL Transformation problem
Language : C#
Platform : .NET
I'm trying to transform XML file from one format to another using xsl transformation(using XSLTransform class). But the problem is if my XML file contains the attribue "xmlns" the XSL Transform class is not able to transform the XML document. It is not able to traverse the node further. But if i remove the xmlns attribute my code is working fine. Any comments???
Below is the XML document:-
<?xml version="1.0" encoding="utf-8" ?>
<Service xmlns="http://in.abc.com/Automation/Simple" name="TestService" destination="Something">
<SimpleDetailStructure name="ProjectDetails">
<Section name="ProjectProfile">
<Item name="id" type="int" key="Primary">10001</Item>
<Item name="fullname" type="sring">test</Item>
<Item name="shortname" type="string">Bank</Item>
<Item name="salary" type="double">25000</Item>
</Section>
<Section name="Positions">
<Item name="id" type="int">1</Item>
<Item name="startdate" type="string">21/04/2005</Item>
<Item name="enddate" type="string">21/04/2008</Item>
</Section>
<Section name="Technology">
<Item name="id" type="int">1</Item>
<Item name="name" type="string">.Net Framework</Item>
</Section>
<Section name="Skills">
<Item name="id" type="int">100</Item>
<Item name="Name" type="string">.Net</Item>
</Section>
<Section name="ODC">
<Item name="id" type="int">100</Item>
<Item name="Name" type="string">LapTop</Item>
</Section>
</SimpleDetailStructure>
</Service>
Below is the XSL file:-
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<SimpleDetailStructure>
<xsl:for-each select="Service/SimpleDetailStructure/Section">
<xsl:element name="{@name}">
<xsl:for-each select="*">
<xsl:element name="{@name}">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:element>
</xsl:for-each>
</xsl:element>
<xsl:text>#xa;</xsl:text>
</xsl:for-each>
</SimpleDetailStructure>
</xsl:template>
</xsl:stylesheet>
Below is the C# code to transform the file.
string outPut=string.Empty;
XmlReader xr;
XmlTextWriter objw= new XmlTextWriter(@"D:\xsl\test.xml",System.Text.Encod ing.UTF8);
//XmlWriter objxmlw;
XmlDocument xmlDoc= new XmlDocument();
XslTransform xslt = new XslTransform();
xslt.Load(@"D:\xsl\XMLUtility\Docs\ActualXSL.xsl") ;
xmlDoc.Load(@"D:\xsl\XMLUtility\Docs\ActualXML.xml ");
xr = xslt.Transform(xmlDoc,null);
xmlDoc=null;
xr.MoveToContent();
return xr.ReadOuterXml();
|