Documents with embedded stylesheets may fail to transform with libxslt when they reference namespaces from their surrounding scope (attached, moop_0.xml). That example is a particularly tricky case as the stylesheet relies on a qname-in-content, but more straightforward examples involving literal result elements also fail currently.
With a slight modification, making a copy the root element namespace declaration on its child (attached, moop_1.xml), the transformation succeeds. However, this demonstrates another issue, as the stylesheet is removed rather than copied from the source document. Saxon 6.5.5 produces the same result for both documents (attached, moop_expected_output.xml). I think libxslt should operate similarly, rather than keeping its current behaviour (attached, xsltproc_output.txt). This is a corner case seems rather underspecified, but see: <http://www.w3.org/TR/xslt#section-Embedding-Stylesheets> The example given doesn't address the namespace/qname issue closely, but does imply that the internal stylesheet should be part of the input document, rather than being removed from it. I have suggested a few possible changes (attached, libxslt_internal_transform.patch) but it needs someone who gets the implications to pick an option. It seems that the xmlDOMWrap* family of functions are an (incomplete?) attempt to address this category of namespace issues, and could potentially solve the whole problem, whereas the first two suggestions would not fix the inital document above. Martin
<!DOCTYPE xmp:moop [<!ATTLIST xsl:transform id ID #IMPLIED>]> <?xml-stylesheet type="text/xsl" href="#transform"?> <xmp:moop xmlns:xmp="http://example.com/ns" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:transform id="transform" version="1.0"> <xsl:template match="/xmp:moop"> <xsl:copy-of select="."/> </xsl:template> </xsl:transform> </xmp:moop>
<!DOCTYPE xmp:moop [<!ATTLIST xsl:transform id ID #IMPLIED>]> <?xml-stylesheet type="text/xsl" href="#transform"?> <xmp:moop xmlns:xmp="http://example.com/ns" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:transform id="transform" version="1.0" xmlns:xmp="http://example.com/ns"> <xsl:template match="/xmp:moop"> <xsl:copy-of select="."/> </xsl:template> </xsl:transform> </xmp:moop>
<?xml version="1.0" encoding="utf-8"?><xmp:moop xmlns:xmp="http://example.com/ns" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:transform id="transform" version="1.0"> <xsl:template match="/xmp:moop"> <xsl:copy-of select="."/> </xsl:template> </xsl:transform> </xmp:moop>
$ xsltproc -V
Using libxml 20632, libxslt 10124 and libexslt 813
xsltproc was compiled against libxml 20632, libxslt 10124 and libexslt 813
libxslt 10124 was compiled against libxml 20632
libexslt 813 was compiled against libxml 20632
$ xsltproc -v /moop_0.xml
xsltLoadStylesheetPI : found PI href=#transform
xsltLoadStylesheetPI : Reference to ID #transform
reusing dictionary from moop_0.xml for stylesheet
creating dictionary for stylesheet
reusing dictionary from (null) for stylesheet
xsltParseStylesheetProcess : found stylesheet
xsltPrecomputeStylesheet: removing ignorable blank node
xsltCompilePattern : parsing '/xmp:moop'
error
xsltCompileStepPattern : no namespace bound to prefix xmp
compilation error: element template
xsltCompilePattern : failed to compile '/xmp:moop'
parsed 1 templates
freeing dictionary from stylesheet
creating dictionary for stylesheet
reusing dictionary from moop_0.xml for stylesheet
xsltPrecomputeStylesheet: removing ignorable blank node
compilation error: file moop_0.xml line 3 element moop
xsltParseStylesheetProcess : document is not a stylesheet
freeing dictionary from stylesheet
$ xsltproc -v /moop_1.xml
xsltLoadStylesheetPI : found PI href=#transform
xsltLoadStylesheetPI : Reference to ID #transform
reusing dictionary from moop_1.xml for stylesheet
creating dictionary for stylesheet
reusing dictionary from (null) for stylesheet
xsltParseStylesheetProcess : found stylesheet
xsltPrecomputeStylesheet: removing ignorable blank node
template has 1 inherited namespaces
xsltCompilePattern : parsing '/xmp:moop'
xsltCompilePattern : parsed /xmp:moop, default priority 0.500000
added pattern : '/xmp:moop' priority 0.500000
parsed 1 templates
Resolving attribute sets references
Creating sub-dictionary from stylesheet for transformation
Registered 0 modules
reusing transformation dict for output
Registering global variables
xsltProcessOneNode: no template found for /
xsltProcessOneNode: applying template '/xmp:moop' for moop
xsltCopyOf: select .
xsltCopyOf: result is a node set
xsltCopyTextString: copy text
xsltCopyTextString: copy text
freeing transformation dictionary
<?xml version="1.0"?>
<xmp:moop xmlns:xmp="http://example.com/ns"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xmp:moop>
freeing dictionary from stylesheet
libxslt_embedded_stylesheet.patch
Description: Binary data
_______________________________________________ xslt mailing list, project page http://xmlsoft.org/XSLT/ [email protected] http://mail.gnome.org/mailman/listinfo/xslt
