Subject: [xsl] Default namespace in result document From: Phil Endecott <spam_from_xslt_list@xxxxxxxxxxxx> Date: Wed, 07 Dec 2005 18:35:10 +0000 |
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 version="1.0"?> <foo xmlns="http://example.com/foo"> <blah/> </foo>
<?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: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>
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...)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem with doctype-syst, Axel Kesten | Thread | Re: [xsl] Default namespace in resu, andrew welch |
Re: [xsl] Encoding problem or what , Geert Josten | Date | Re: [xsl] Variable assign, Dimitre Novatchev |
Month |