xsl-list
[Top] [All Lists]

Default namespace in result document

2005-12-07 11:35:10
(I had some problem sending this earlier; appologies if you see it twice.)

Dear All,

I have been using XSLT successfully for a few years now but have never
tried to make namespaces work, mainly because at least one component in
the system has not supported them properly.  I've now tried using them
for the first time and although I get a result document that is correct
it's not quite what I had expected.  Here's an example:

[XML input:]

<?xml version="1.0"?>
<foo xmlns="http://example.com/foo";>
  <blah/>
</foo>


[XSLT:]

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0"
  xmlns:foo="http://example.com/foo";>

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <foo:root>
      <xsl:apply-templates mode="copy"/>
    </foo:root>
  </xsl:template>

  <xsl:template match="*" mode="copy">
    <xsl:copy>
      <xsl:apply-templates mode="copy"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


So the stylesheet contains literal result elements in namespace foo, and
also copies elements from the input XML that are in namespace foo.  I
was hoping to get something like this:

<?xml version="1.0"?>
<root xmlns="http://example.com/foo";>
  <foo>
    <blah/>
  </foo>
</root>

i.e. the default namespace is defined on the root element, and no
namespace things are used anywhere else.  But instead, using libxslt
version 1.1.15, I get this:

<?xml version="1.0"?>
<foo:root xmlns:foo="http://example.com/foo";>
  <foo xmlns="http://example.com/foo";>
    <blah/>
  </foo>
</foo:root>

This is not ideal because it makes files much larger than they need to
be.  I guessed that there would be some xsl:output attribute to select a
default namespace but I can't see anything that does exactly this.  I
can't help feeling that I've missed something obvious.  Can someone
suggest what I need to do?

(I assume that this is also an issue for people trying to generate
"HTML-compatible XSLT" - not something I have tried to do yet...)

Many thanks,

--Phil.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--