Project

Profile

Help

Workaround for legacy XSLT 1.0 disable-output-escaping='yes'

Added by Hrafn Malmquist over 4 years ago

Hi there

I'll admit I'm not an export in XSLT by any long shot, in fact I struggle to understand the functional sequence for which things happen. It's probably the backward way I have been introduced to it, via the XMLUI interface of DSpace.

I've recently had reason to see if I can upgrade from XSLT 1 to 2, a long standing issue (see: https://jira.duraspace.org/browse/DS-995) that is somewhat irrelevant since the next big release of DSpace will move over to a REST API/Angular combination. Meanwhile, switching to XSLT 2.0 means using Saxon instead of Xalan which is Cocoon's default translator (I've followed this: http://blog.reverycodes.com/archives/000034.html).

However there is the <xsl:text disable-output-escaping='yes'> issue which I can't solve for the heading DOCTYPE

<xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;
</xsl:text>

becomes

<?javax.xml.transform.disable-output-escaping >&lt;!DOCTYPE html&gt;
<?javax.xml.transform.enable-output-escaping >

I've tried Googling and I've tried Mr. Kay's fine book XSLT 2.0 3rd Edition.

I've tried using character mapping but maybe I'm doing something wrong.

The whole XSL file can be viewed here: https://github.com/DSpace/DSpace/blob/dspace-6_x/dspace-xmlui-mirage2/src/main/webapp/xsl/core/page-structure.xsl

Any suggestions on how this can be solved would be very welcome.

Best regards, Hrafn Malmquist developer, University of Edinburg


Replies (5)

Please register to reply

RE: Workaround for legacy XSLT 1.0 disable-output-escaping='yes' - Added by Michael Kay over 4 years ago

Firstly, you don't actually need to change your code; Saxon still supports disable-output-escaping, though it is deprecated.

The main reason it's a bad idea to use it is that it means your stylesheet only works if the output is going straight to a serializer, which makes the code less reusable. It's also discouraged because there's usually a better way of achieving what you want to do.

The use of disable-output-escaping means that the transformation engine needs a back-channel to communicate with the serializer, and the way it does this is by injecting processing instructions such as javax.xml.transform.enable-output-escaping into the event stream (IIRC this si actually defined in a JAXP specification). If the processing instructions are visible, that's because you are sending the output to a destination that doesn't understand them. So we need to examine how you are running the transformation (perhaps you're sending the output to a DOMResult?)

As it happens there's a much better way of getting the HTML5 DOCTYPE declaration into your output: XSLT 3.0 allows you to specify

<xsl:output method="html" html-version="5"/>

and the declaration will then be generated automatically.

But this is still only going to work if the transformation output is sent directly to a serializer, not if it is sent to something like a DOMResult.

RE: Workaround for legacy XSLT 1.0 disable-output-escaping='yes' - Added by Hrafn Malmquist over 4 years ago

Hi

Ok. I am using Saxon 8.7.

XSL now reads:

<xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" xmlns:dri="http://di.tamu.edu/DRI/1.0/" xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:dim="http://www.dspace.org/xmlns/dspace/dim" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:confman="org.dspace.core.ConfigurationManager" exclude-result-prefixes="i18n dri mets xlink xsl dim xhtml mods dc confman">

<xsl:output method="xhtml" encoding="UTF-8" indent="yes"/>

but there is no DOCTYPE outputted.

If I switch to Saxon-HE I get an error because of the xmlns:confman Java class. It's a strange error because it complains about a method "Q", but there is no method Q.

Class is here: https://github.com/DSpace/DSpace/blob/dspace-6_x/dspace-api/src/main/java/org/dspace/core/ConfigurationManager.java

What can I do using Saxon 8.7 to output a valid DOCTYPE for HTML ?

RE: Workaround for legacy XSLT 1.0 disable-output-escaping='yes' - Added by Hrafn Malmquist over 4 years ago

So the XSL reads:

<xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" xmlns:dri="http://di.tamu.edu/DRI/1.0/" xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/TR/xlink/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:dim="http://www.dspace.org/xmlns/dspace/dim" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:confman="org.dspace.core.ConfigurationManager" exclude-result-prefixes="i18n dri mets xlink xsl dim xhtml mods dc confman">

RE: Workaround for legacy XSLT 1.0 disable-output-escaping='yes' - Added by Martin Honnen over 4 years ago

I think the first version of Saxon to implement the W3C XSLT 2 recommendation was Saxon 8.9 but Saxon has moved on to XSLT 3, as implemented by Saxon 9.8 and 9.9. Not sure why you have chosen 8.7 which seems completely outdated and probably doesn't implement the final and official XSLT 2 recommendation.

I am not sure since when <xsl:output method="html" html-version="5"/> is supported, but I would recommend to move to a current version of Saxon (9.9) and not to rely on Saxon 8.7 if you want to use such features.

RE: Workaround for legacy XSLT 1.0 disable-output-escaping='yes' - Added by Michael Kay over 4 years ago

As Martin says, 8.7 is a very ancient release and not supported any more. It's certainly too old to include support for the HTML5 DOCTYPE declaration.

Your original symptoms, where the <?javax.xml.transform.enable-output-escaping > was somehow exposed, suggests to me that we need to see how you are invoking Saxon from your application.

I'm afraid I don't know DSpace; I can't help you with DSpace problems, and I don't know if it imposes any constraints on which Saxon versions you can use.

    (1-5/5)

    Please register to reply