[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] how to avoid hardcoding xpath-default-namespace in xsl:stylesheet?


Subject: Re: [xsl] how to avoid hardcoding xpath-default-namespace in xsl:stylesheet?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 11 Apr 2014 23:51:39 +0100

On 11/04/2014 23:35, Larry Evans wrote:
 ><!--How to avoid this hardcoding of xpath-default-namespace?-->
<xsl:template match="html">

the model really is that you _want_ to hardcode the namespace just as you have hardcoded the local-name "html" they are just two parts of the same name. However if you want to match (say) html in no-namepsace and html in the xhtml namespace you could use


html|h:html

where h is bound to http:/www.w3.org/1999/xhtml

or you could use

*:html

which matches html in any namespace

or to do exactly what you said, of just matching the namespace used in the source you can do a two pass strategy that first uses a stylesheet that just uses namespace-uri(/*) on the source document to get the namespace, then transforms the main stylesheet to set the default namespace, then transforms the document with the generated stylesheet.

or finally you can do a two pass strategy that first transforms the source document to a known namespace (say no-namespace") just using

<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="">

then you can transform this document which has a known namespace structure.

David


Current Thread
Keywords