Trouble transforming document element

T

Tor Hovland

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top