For HTML with embedded Javascript, I need to output > as > rather than as >
In XSLT I’m doing
<xsl:character-map name="a"> <!-- This charmap is necessary for embedding CSS that contains '>' combinators --> <xsl:output-character character=">" string=">"/> </xsl:character-map>
and
<xsl:output method="xhtml" indent="no" encoding="UTF-8" use-character-maps="a" omit-xml-declaration="no" html-version="5.0" doctype-public="" doctype-system=""/>
In RESTXQ I tried the following:
I created a document called html-charmap.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?> <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization"> <use-character-maps> <character-map character=">" map-string=">"/> </use-character-maps> </serialization-parameters>
It resides in the directory where the xqm is located. The xqm contains this function:
module namespace my = 'my';
declare %rest:GET %rest:path("/charmap/test") %output:method("xhtml") %output:html-version("5.0") %output:parameter-document("html-charmap.xml") %rest:produces("text/html") function my:html() { <html> <head> <title>Charmap Test</title> <meta charset="UTF-8"/> <script> alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode and 1
0 is ' + (1 > 0)</script>
</head> <body> <h1>Charmap Test</h1> <p>></p> <p>></p> </body> </html> };
When I retrieve /charmap/test, all > characters are still escaped as >
When I change %output:parameter-document to %output:parameter-document("tml-charmap.xml"), BaseX doesn’t complain about the missing parameter document.
What am I doing wrong?
In XSLT 3 with Saxon, I can also do
<xsl:output method="xhtml" indent="yes" include-content-type="no" encoding="UTF-8" parameter-document="html-charmap.xml" omit-xml-declaration="no" html-version="5.0" doctype-public="" doctype-system=""/>
and this will use html-charmap.xml and it will complain when it’s the wrong file name.
Gerrit
Correction & for completeness: I forgot a closing parenthesis in Javascript (but this isn’t causing the unused character map issue, of course…):
On 22.06.2022 11:53, Imsieke, Gerrit, le-tex wrote:
<script> alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode and 1
0 is ' + (1 > 0)</script>
<script> alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode and 1
0 is ' + (1 > 0) )</script>
Hi Gerrit,
Right, the »parameter-document« serialization parameter is currently not supported by RESTXQ, as this might cause too many conflicts at runtime. You can try »use-character-maps« instead (with and without RESTXQ, with a slightly non-standard syntax):
declare %rest:path("/test") %output:use-character-maps(">=>,1=3") function _:html() { <xml> 1 > 2 </xml> };
declare option output:use-character-maps '>=>,1=3'; <script> 1 > 2 </script>
serialize(<xml> 1 > 2 </xml>, map { 'use-character-maps': '>=>,1=3' } )
…and the standard way, for fn:serialize, as a reminder:
serialize(<xml> 1 > 2 </xml>, map { 'use-character-maps': map { '>': '>', '1': '3' } } )
Keys and values are separated by the equal sign; pairs are separated by commas. Separators that are to be defined as keys or values can be encoded as entities (see the updated article on serialization parameters [1]).
Hope this helps, Christian
On 22.06.2022 14:31, Christian Grün wrote:
Right, the »parameter-document« serialization parameter is currently not supported by RESTXQ, as this might cause too many conflicts at runtime. You can try »use-character-maps« instead (with and without RESTXQ, with a slightly non-standard syntax):
declare %rest:path("/test") %output:use-character-maps(">=>,1=3") function _:html() { <xml> 1 > 2 </xml> };
Excellent, I’ll take undocumented non-standard features for $500, Alex. Er, Christian. And you just documented it: https://docs.basex.org/index.php?title=Serialization&type=revision&d...
Thanks!
Gerrit
basex-talk@mailman.uni-konstanz.de