Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2006, 07:54 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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();
 
Old November 23rd, 2006, 08:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

http://www.biglist.com/lists/xsl-lis.../msg00772.html

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 23rd, 2006, 01:24 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Or see the link in the first post in this forum about namespaces.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl transformation ... rajesh_css XSLT 5 September 30th, 2008 12:37 AM
XSL-Transformation atulshin XSLT 4 September 15th, 2008 06:37 AM
WML and XSL transformation. Feodorov XSLT 2 February 13th, 2008 05:00 PM
XSL transformation problem kawal.singh XSLT 2 December 5th, 2006 05:58 AM
XSL transformation Thodoris XML 0 May 20th, 2004 08:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.