Issues processing xsl:namespace-alias
There were at least three old issues regarding xsl:namespace-alias (cf. https://bugzilla.gnome.org/show_bug.cgi?id=313711, https://bugzilla.gnome.org/show_bug.cgi?id=341325 and https://bugzilla.gnome.org/show_bug.cgi?id=341392). These bugs have been reported by Oleg Paraschenko and by kbuchcik@4commerce.de, and have been closed ages ago. Nevertheless, these bugs still exist in the current version.
Bug 313711
Apply the following stylesheet to itself:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" version="1.0">
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:template match="xsl:stylesheet">
<xsl:copy>
<xsl:copy-of select="node()|@*"/>
<axsl:template match="none"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The result should be:
(...)
<xsl:template match="none"/>
(...)
But the result is:
(...)
<axsl:template xmlns:axsl="http://www.w3.org/1999/XSL/Transform" match="none"/>
(...)
Bug 341325
Apply the following stylesheet to itself:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias" exclude-result-prefixes="axsl xsl">
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<axsl:stylesheet version="1.0"/>
</xsl:template>
</xsl:stylesheet>
The result should be:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"/>
But the result is:
<?xml version="1.0" encoding="utf-8"?>
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" version="1.0"/>
Bug 341392
Scenario A
Apply the following stylesheet to itself:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="urn:test:ext" extension-element-prefixes="ext">
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:variable name="bar">
<bar xmlns:ext="urn:test:ext"/>
</xsl:variable>
<xsl:template match="/">
<foo>
<xsl:copy-of select="$bar"/>
</foo>
</xsl:template>
</xsl:stylesheet>
The result should be:
<?xml version="1.0" encoding="utf-8"?>
<foo>
<bar/>
</foo>
But the result is:
<?xml version="1.0" encoding="utf-8"?>
<foo>
<bar xmlns:ext="urn:test:ext"/>
</foo>
Scenario B
Apply the following stylesheet to itself:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext-literal="urn:test:ext" xmlns:ext-target="urn:test:ext" extension-element-prefixes="ext-target">
<xsl:namespace-alias stylesheet-prefix="ext-literal" result-prefix="ext-target"/>
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<foo xmlns:ext="urn:test:ext"/>
</xsl:template>
</xsl:stylesheet>
The result should be:
<?xml version="1.0" encoding="utf-8"?>
<foo/>
But the result is:
<?xml version="1.0" encoding="utf-8"?>
<foo xmlns:ext="urn:test:ext" xmlns:ext-literal="urn:test:ext"/>
Attachment
Find attached a ZIP file that contains the following: NamespaceBug.zip
.
| Test.cmd Batch that orchestrates the XSLT processors
| 313711.xsl Test case for bug 313711
| 341325.xsl Test case for bug 341325
| 341392a.xsl Test case for bug 341392, scenario A
| 341392b.xsl Test case for bug 341392, scenario B
| xsltproc.txt Version and usage hints for xsltproc
| transform.txt Version and usage hints for Saxonica
| MSXSL.txt Version and usage hints for MSXSL
| NXSLT.txt Usage hints for NXSLT (more details, see below)
| LibXSLT_vs_Saxonica.diff Output of 'diff -Naur LibXSLT Saxonica'
| LibXSLT_vs_MSXSL.diff Output of 'diff -Naur LibXSLT MSXSL'
| LibXSLT_vs_NXSLT.diff Output of 'diff -Naur LibXSLT NXSLT'
|
+---LibXSLT Output of xsltproc
| 313711.xsl
| 341325.xsl
| 341392a.xsl
| 341392b.xsl
|
+---Saxonica Output of transform
| 313711.xsl
| 341325.xsl
| 341392a.xsl
| 341392b.xsl
|
+---MSXSL Output of MSXSL
| 313711.xsl
| 341325.xsl
| 341392a.xsl
| 341392b.xsl
|
\---NXSLT Output of NXSLT
313711.xsl
341325.xsl
341392a.xsl
341392b.xsl
XSLT processors
I've used the following XSLT processors:
- libxslt/xsltproc, under MSys2 (https://www.msys2.org/)
mingw32/mingw-w64-i686-libxslt 1.1.32-1 [installed]
XML stylesheet transformation library (mingw-w64)
mingw64/mingw-w64-x86_64-libxslt 1.1.32-1 [installed]
XML stylesheet transformation library (mingw-w64)
-
Saxonica/transform (https://sourceforge.net/projects/saxon/files/Saxon-HE/9.8/SaxonHE9-8-0-15N-setup.exe/download)
-
MSXSL (https://www.microsoft.com/en-us/download/details.aspx?id=21714)
-
NXSLT
Since NXSLT and NXSLT2 from Oleg Tkachenko (cf. http://www.tkachenko.com/blog/archives/000719.html) are not available anymore I've used a very simple C# console application named NXSLT as well.
XslCompiledTransform xslCompiledTransform = new XslCompiledTransform(true);
XsltSettings xsltSetting = new XsltSettings(true, true);
XmlResolver xmlUrlResolver = new XmlUrlResolver();
xslCompiledTransform.Load(xslFile, xsltSetting, xmlUrlResolver);
xslCompiledTransform.Transform(xmlFile, outFile);