Project

Profile

Help

Saxon serialization attributes

Added by Anonymous about 18 years ago

Legacy ID: #3943635 Legacy Poster: fackel (fackel)

Hi! I found some interesting serialization attributes in the Saxon Javadoc and try to figure out how to use them (properly). I'm referring especially to the attributes byte-order-mark and escape-uri-attributes. 1. How do I set these serialization attributes in the XSLT stylesheet? I tried something like this, but it doesn't do it: <xsl:stylesheet version="2.0" xmlns:xsl=... xmlns:saxon="http://saxon.sf.net/"> <xsl:output method="html" encoding="utf-8" saxon:escape-uri-attributes="no"/> The stylesheet compiles fine but the attribute has no effect. 2. Setting the serialization attributes on the transformer (using setOutputProperty()) works fine for the main output but doesn't affect the output generated by xsl:result-document. How do I make the serialization settings apply to xsl:result-document output too? (If it matters: I'm using Saxon 8.8)


Replies (4)

Please register to reply

RE: Saxon serialization attributes - Added by Anonymous about 18 years ago

Legacy ID: #3943970 Legacy Poster: Michael Kay (mhkay)

The attributes escape-uri-attributes and byte-order-mark are both standard XSLT 2.0 attributes, so they shouldn't go in the Saxon namespace. However, because they are new in XSLT 2.0, they aren't supported directly by JAXP, which is why their constants are listed in SaxonOutputKeys and not in the JAXP OutputKeys class. xsl:result-document allows serialization properties to be specified by means of AVTs, for example byte-order-mark="{$byte-order-mark}". These can refer to stylesheet parameters, so the required values can be supplied at run-time in the same way as any other parameter. I decided not to provide any other mechanism in the Saxon API for this until it emerges what JAXP intends to do about it.

RE: Saxon serialization attributes - Added by Anonymous about 18 years ago

Legacy ID: #3944035 Legacy Poster: fackel (fackel)

My initial understanding of XSLT 2 was the one you discribed, but at some point down the road I got confused (because xsl:result-document didn't work as I wanted) and I started prefixing with the Saxon namespace what really didn't help. But now I set the attribute on xsl:output (without saxon) and the output, both main and result-documents, is as I expect it. But now I see a problem with xsl:result-document and these serialization attributes in Saxon: It looks to me like the attributes on xsl:result-document (when set in the stylesheet) don't have any effect. The output of xsl:result-document always matches the attributes set on xsl:output. Is this once again my confusion or is it a Saxon feature?

RE: Saxon serialization attributes - Added by Anonymous about 18 years ago

Legacy ID: #3944068 Legacy Poster: Michael Kay (mhkay)

If the attributes on xsl:result-document aren't having any effect, then you're doing something wrong, so we'll have to find out what you're doing. Please supply a simple example to demonstrate the problem.

RE: Saxon serialization attributes - Added by Anonymous about 18 years ago

Legacy ID: #3957342 Legacy Poster: fackel (fackel)

To get more precise, it's attribute escape-uri-attributes that doesn't give the expected result when set on xsl:result-document. The output produced through xsl:result-document always corresponds to the attribute value of escape-uri-attributes set on xsl:output. Note that attribute byte-order-mark works as expected on both xsl:output and xsl:result-document. (I didn't check the other serialization attributes yet, as I don't need them.) I used Saxon-B 8.8. --------------- My stylesheet (play with the attributes values on xsl:output and xsl:result-document inthere and check the output in file result-document.htm): <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all"> <xsl:output method="html" encoding="utf-8" escape-uri-attributes="no" byte-order-mark="no"/> <xsl:template match="/"> <xsl:call-template name="out"> <xsl:with-param name="title">OUTPUT</xsl:with-param> </xsl:call-template> <!-- escape-uri-attributes doesn't work - it defaults to xsl:output. byte-order-mark works fine. --> <xsl:result-document href="result-document.htm" escape-uri-attributes="yes" byte-order-mark="yes"> <xsl:call-template name="out"> <xsl:with-param name="title">RESULT-DOCUMENT</xsl:with-param> </xsl:call-template> </xsl:result-document> </xsl:template> <xsl:template match="img"> <xsl:variable name="uri" select="unparsed-entity-uri(@name)"/> <img src="file:///{$uri}"/> </xsl:template> <xsl:template name="out"> <xsl:param name="title">none</xsl:param> <html><head><title><xsl:value-of select="$title"/></title></head> <body><xsl:apply-templates select="//img"/></body></html> </xsl:template> </xsl:stylesheet> --------------- My XML test file: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE bongo [ <!NOTATION jpg SYSTEM ""> <!ENTITY img SYSTEM "c:/temp/xslTest/äöü.jpg" NDATA jpg> ]> <bongo> <img name="img"/> </bongo>

    (1-4/4)

    Please register to reply