I am trying to dynamically generate an XSLT document from an XSLT stylesheet. In principle this works, of course, but I do not get the namespaces working. I want to have the generated XSLT elements to be prefixed with "xsl" prefix:
<xsl:stylesheet ...>
rather than
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform">
I played around with namespace="" of xsl:element and with xsl:namespace but I do not get it working (xslt2/saxon available)
Any hints?
If you want to use XSLT to create XSLT code then using http://www.w3.org/TR/xslt20/#element-namespace-alias helps e.g.
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:axsl="file://namespace.alias">
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:template match="/">
<axsl:stylesheet version="2.0">
<xsl:apply-templates/>
</axsl:stylesheet>
</xsl:template>
<xsl:template match="elements">
<axsl:template match="/">
<axsl:comment select="system-property('xsl:version')"/>
<axsl:apply-templates/>
</axsl:template>
</xsl:template>
<xsl:template match="block">
<axsl:template match="{.}">
<fo:block><axsl:apply-templates/></fo:block>
</axsl:template>
</xsl:template>
</xsl:stylesheet>
I found the solution:
<xsl:element name="xsl:stylesheet">
</xsl:element>
does the job! (i.e., avoid using namespace="" but explicitely list the namespace prefix)
The xsl:namespace-alias
instruction was designed having exactly this use case in mind -- just start using it in your work.
Here is a real-world example:
http://dnovatchev.wordpress.com/2006/10/21/a-stylesheet-to-write-xslt-code/