David Carlisle
With saxon, I think that generating a namespace node in the result
based on a variable value you need to do something like <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:saxon="http://icl.com/saxon"
extension-element-prefixes="saxon"
>
<xsl:output method="xml" indent="yes"/>
<xsl:param name="p" select="'foo'"/>
<xsl:param name="n" select="'http://x/y/z'"/>
<xsl:template match="/">
<xsl:variable name="x">
<xsl:element name="{$p}:x" namespace="{$n}"/>
</xsl:variable>
<xxx path="{$p}:that">
<xsl:for-each select="saxon:node-set($x)/*/namespace::*[name()=$p]">
<xsl:copy/>
</xsl:for-each>
<!--
<xsl:copy-of select="saxon:node-set($x)/*/namespace::*"/>
- -->
</xxx>
</xsl:template>
</xsl:stylesheet>
applying this to anything (eg itself) gives you
<?xml version="1.0" encoding="utf-8" ?>
<xxx xmlns:foo="http://x/y/z" path="foo:that"/> But this relies on some grey areas in the spec about copying namespace
nodes, (which saxon, as Mike pointed out on this list some time back,
interprets slightly differently for copy and copy-of.)
Mike Kay responds (July 2000)
Yes I know:-)
But perhaps in version 1+x making the current saxon behaviour for copy
the defined behaviour (for copy and copy-of) would probably be an
improvement.
Still it's a bit of a hack, especially as node-set's an extension.
so an xsl:namespace-declaration that worked like xsl:attribute
would probably be a good addition as well.
And David finishes with :-)
so, a version that only explictly copies element and attribute nodes.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:saxon="http://icl.com/saxon"
extension-element-prefixes="saxon"
>
<xsl:output method="xml" indent="yes"/>
<xsl:param name="p" select="'foo'"/>
<xsl:param name="n" select="'http://x/y/z'"/>
<xsl:template match="/">
<xsl:variable name="x">
<xxx path="{$p}:that">
<xsl:attribute name="{$p}:x" namespace="{$n}"/>
</xxx>
</xsl:variable>
<xsl:for-each select="saxon:node-set($x)/*">
<xsl:copy>
<xsl:copy-of select="@*[local-name()!='x']"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
bash-2.01$ saxon ns3.xsl ns3.xsl
<?xml version="1.0" encoding="utf-8" ?>
<xxx xmlns:foo="http://x/y/z" path="foo:that"/>
as it doesn't use namespace:: this also works with xt (once you change
the extension namespace)
|