[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Default namespace in result document

Subject: Re: Default namespace in result document
From: Phil Endecott <spam_from_xslt_list@xxxxxxxxxxxx>
Date: Mon, 12 Dec 2005 23:10:54 +0000
xml non default namespace
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"
  version="1.0"
  xmlns="http://example.com/foo"
  xmlns:f="http://example.com/foo"
  exclude-result-prefixes="f">

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

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

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

</xsl:stylesheet>



Input:

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



Result:

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


Can anyone suggest anything better?


--Phil.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.