Subject: RE: [xsl] XSLT2 variables / nodesets and their namespace From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Fri, 21 Jan 2005 12:03:01 -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? It will do so if you construct it using a literal result element, because an LRE copies its namespace context from the stylesheet to the result tree. > > 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. > > ie: > > <?xml version="1.0" encoding="utf-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0" > 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. You need to show an example of this. It all depends on how you construct the elements in the temporary tree. > > 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"/> > </xsl:variable> The first xsl:copy-of is an error because you can't refer to $head within its own definition. This has nothing to do with namespaces. > > 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" > xmlns:f="http://www.w3.org/1999/xhtml" > xmlns="http://www.w3.org/1999/xhtml" > version="2.0" > exclude-result-prefixes="f" > > > [...] > <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"/> > </xsl:variable> > I think you need to show us what you did first, and what output it produced, and what output you wanted, rather than showing us all the ways you tried to fix the problem. Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSLT2 variables / nodesets an, Tom Schutzer-Weissma | Thread | RE: [xsl] XSLT2 variables / nodeset, Tom Schutzer-Weissma |
Re: [xsl] replace table by one code, António Mota | Date | Re: [xsl] XSLT2 variables / nodeset, David Carlisle |
Month |