Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 07:10 AM
Tor Hovland
Guest
 
Posts: n/a
Default Trouble transforming document element

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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles