Bug #4337
closedbase-uri() call is incorrectly encoding the resulting URI.
0%
Description
Our application requires the base-uri in order to create links. The URI may contain query parameters:
for example : http://localhost:9090/path/to/app?param1=1¶m2=2¶m3=3
We get to the URI like this...
<xsl:template match="/" >
<xsl:variable name="url" select="base-uri(.)"/>
.
.
.
The result that we get for $url is
http://localhost:9090/path/to/app?param1=1&param2=2&param3=3
We don't think this correct. Replacing & with an entity should be something that happens during serialization.
We expect the result to be:
http://localhost:9090/path/to/app?param1=1¶m2=2¶m3=3
As a workaround we're currently doing this:
<xsl:template match="/">
<xsl:variable name="url" select="replace(base-uri(.), 'amp;','')" />
Thanks
Updated by Michael Kay over 4 years ago
How was the base URI set up in the first place? My suspicion would be that the &
substrings are present in the base URI supplied to Saxon, rather than being something that the base-uri() function has added.
Updated by Jorge Williams over 4 years ago
We simply type in the URI into the location bar in Safari.
Updated by Michael Kay over 4 years ago
And how do you invoke the transformation?
Updated by Jorge Williams over 4 years ago
We start with a server side transformation that sets up the HTML wrapper to bootstrap SaxonJS, the source document is dynamically generated and the URI is in an atom link.
So on the server side we do something like this:
<xsl:template expand-text="no" name="xsl:initial-template">
<xsl:variable name="self" select="/*/atom:link[@rel='self']/@href"/>
<html lang="en">
<head>
<script src="/resources/Saxon-JS/SaxonJS.js"></script>
<script> window.onload = function() { SaxonJS.transform({ stylesheetLocation: "/resources/xsl/document.sef", sourceLocation: "<xsl:value-of select="$self"/>" }); } </script>
.
.
.
.
</xsl:template>
Updated by Michael Kay over 4 years ago
So -- conjecture -- the HTML that you're generating server side will be serialized and the "sourceDocument" URL contained in the HTML has been ampersand-escaped. But when it's read by the HTML parser, the contents of a script element don't get unescaped.
The HTML serialization method isn't supposed to apply escaping to the contents of a script
element, precisely because the HTML parser doesn't apply unescaping. But perhaps you didn't generate the document using the HTML output method?
Updated by Jorge Williams over 4 years ago
Confirmed that "sourceDocument" is ampersand-escaped by server side transform:
<script src="/resources/Saxon-JS/SaxonJS.js"></script><script> window.onload = function() { SaxonJS.transform({ stylesheetLocation: "/resources/xsl/document.sef", sourceLocation: "http://localhost:8080/test/?bar=true&foo=true" }); } </script>
Setting output method to HTML...
<xsl:output method="html" />
... had no effect on the encoding of the "sourceDocument" url.
Updated by Michael Kay over 4 years ago
Two explanations come to mind for the contents of <script>
being escaped:
(a) the script element is in a namespace, e.g. the XHTML namespace
(b) the serialization isn't actually being done by the XSLT serializer (for example, the stylesheet output is going to a DOM, which is then serialized using the DOM serializer).
Has the serializer added a <meta>
element with ContentType and encoding? That's usually a good indicator of whether it was produced by the XSLT serializer.
Updated by Jorge Williams over 4 years ago
Removing
xmlns="http://www.w3.org/1999/xhtml"
from the top of the server side stylesheet resolved the issue.
Thank you!
Please register to edit this issue
Also available in: Atom PDF Tracking page