[xsl] Re: Default namespace in result document

Subject: [xsl] Re: Default namespace in result document
From: Phil Endecott <spam_from_xslt_list@xxxxxxxxxxxx>
Date: Mon, 12 Dec 2005 23:10:54 +0000
Dear All,

I've encountered a further problem with namespaces.

Originally I wanted to have a non-default namespace for literal result elements in my stylesheet, and the same namespace - but as the default - in the input and output XML. This doesn't seem to be possible so I've followed your collective advice and made this the default namespace in the stylesheet as well. This works for the simple example that I posted previously.

Unfortunately it fails when I try to match on source document elements. This problem is a FAQ: match="A" doesn't match A in the source document if the source document has a default namespace, even if the stylesheet has the same default namespace.

The normal solution is to use a namespace prefix in the stylesheet, but that's exactly what I'm avoiding to fix the original problem.

I may have a solution that uses a default namespace and a non-default namespace in the stylesheet with the same URI; I use the default namespace in literal result elements and the prefix in match expressions. It looks like this might work, but it is a kludge-upon-a-kludge.

Here's an example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

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

  <xsl:template match="/">

  <xsl:template match="f:foo">



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


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

Can anyone suggest anything better?


Current Thread