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

[xsl] XSLT2 variables / nodesets and their namespace

Subject: [xsl] XSLT2 variables / nodesets and their namespace
From: Tom Schutzer-Weissmann <trmsw@xxxxxxxxxxx>
Date: Fri, 21 Jan 2005 11:51:33 +0000


In XSLT 2, if you create a nodeset as a variable, is there any way to
make it inherit the stylesheet's default namespace?

My stylesheet creates a lot of these variables, which it either copies
straight to output, or processes. This is fine unless the stylesheet has
a default namespace - which is needed for the xhtml output to have a
namespace declaration.


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"      <----- default breaks it

If the default is set, the variables copies to output are decorated with
empty namespace declarations (xmlns=""), and the templates that process
the variables no longer do so. 

Putting a declaration in the variables worked, but I got errors in cases
that mixed the input and another variable and a hardcoded default, eg:

 <xsl:variable name="head">
      <xsl:copy-of select="$head/*"/>
      <xsl:copy-of select="head/*"/>
      <script src="product.js" xmlns="http://www.w3.org/1999/xhtml"/>
      <style href="product.css" xmlns="http://www.w3.org/1999/xhtml"/>

The only way that worked was to prefix all the tags in the variables:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 <xsl:variable name="head">
      <xsl:copy-of select="$head/*"/>
      <xsl:copy-of select="f:head/*"/>
      <f:script src="product.js" xmlns="http://www.w3.org/1999/xhtml"/>
      <f:style href="product.css" xmlns="http://www.w3.org/1999/xhtml"/>

Which I don't like doing because I'm lazy and because it seems
unnecessary. Am I missing something?

Tom SW

Current Thread