Trouble transforming document element

Discussion in 'XML' started by Tor Hovland, Sep 15, 2003.

  1. Tor Hovland

    Tor Hovland Guest

    I'm trying to transform the document element of incoming xml files, however,
    I'm having trouble with namespace references not appearing correctly. Here's
    an example input file:

    <?xml version="1.0" encoding="utf-8" ?>
    <inputdoc xmlns:a="http://www.dummy.org" something="true">
    <hello somethingelse="false" />
    <foo>
    <!-- a comment -->
    <bar />
    </foo>
    </inputdoc>

    All I want to do at the moment is to transform the document element from
    <inputdoc> to <outputdoc> using XSLT. (I do other transformations as well,
    but they are irrelevant for this question.) And yes, I do realise that I'm
    not actually using the namespace http://www.dummy.org anywhere.

    The best output I am able to get is this:

    <?xml version="1.0" encoding="UTF-8"?>
    <outputdoc something="true">
    <hello xmlns:a="http://www.dummy.org" somethingelse="false"/>
    <foo xmlns:a="http://www.dummy.org">
    <!-- a comment -->
    <bar/>
    </foo>
    </outputdoc>

    This is semantically ok, but I would like the namespace references to stay
    attached to the document element. Here is the transformation I'm using:

    <?xml version='1.0' encoding='UTF-8' ?>
    <xsl:transform version='1.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:template match='inputdoc'>
    <xsl:element name='outputdoc'>
    <xsl:apply-templates
    select='*|@*|text()|comment()|processing-instruction()' />
    </xsl:element>
    </xsl:template>
    <xsl:template match='*|@*|text()|comment()|processing-instruction()'>
    <xsl:copy>
    <xsl:apply-templates
    select='*|@*|text()|comment()|processing-instruction()' />
    </xsl:copy>
    </xsl:template>
    </xsl:transform>

    I've tried with both Xalan and the .NET Framework's XslTransform. They
    produce the same results. How should I adapt the transformation so that the
    namespace references are left intact?

    --
    Tor
    Tor Hovland, Sep 15, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. O.B.
    Replies:
    2
    Views:
    3,301
    Damian Brunold
    Feb 7, 2006
  2. David Furey
    Replies:
    0
    Views:
    1,072
    David Furey
    Jun 29, 2003
  3. Yves Forkl
    Replies:
    0
    Views:
    463
    Yves Forkl
    Oct 28, 2003
  4. Mirjana Rakuljic

    Help with transforming XML document

    Mirjana Rakuljic, Nov 7, 2003, in forum: XML
    Replies:
    2
    Views:
    398
    Mirjana Rakuljic
    Nov 8, 2003
  5. samppi
    Replies:
    1
    Views:
    404
    Martin Honnen
    Jan 6, 2008
Loading...

Share This Page