This is probably a duplicate, but I haven't found the answer from any other posts so I will go ahead and ask.
Inside an XSL file, I'd like to have variables that are the namespaces that will be output.
Something like:
<xsl:variable name="some_ns" select="'http://something.com/misc/blah/1.0'" />
Then in a template, do this:
<SomeElement xmlns="$some_ns">
I have had no luck getting this work, even though it seems rather simple.
Thanks for your time.
In XSLT 2.0 you can use
<xsl:namespace>
. But it's only needed in the rare case where you need to generate a namespace declaration that isn't used in the names of elements and attributes. To generate a dynamic namespace for the names of constructed elements and attributes, use the namespace attribute of xsl:element or xsl:attribute, which is an attribute value template so it can be writtenPlease don't hit me with your legs, neither with my own. ;)
produces
To set namespaces dynamically at runtime, use
<xsl:element>
and an attribute value template.If you don't need to set dynamic namespaces, declare a prefix for them and use that:
or even mark the namespace as default: