Leave the object unchanged in XML + XSLT

I am converting XML to (sort) HTML with XSL stylesheets (using Apache Xalan). In XML, there may be objects such as —that should be left as is. At the beginning of the XML file, I have a doctype that references these objects. What should I do to ensure that the object remains unchanged?

<!DOCTYPE article [
<!ENTITY mdash "&mdash;"><!-- em dash -->
]>

gives me SAXParseException: Recursive entity expansion, 'mdash'when meeting &mdashin XML text.

+3
source share
2 answers

Method for determining and using an object :

<!DOCTYPE xsl:stylesheet [<!ENTITY mdash "&#x2014;">]>
<t>Hello &mdash; World!</t>

When processed using the simplest XSLT stylesheet :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
</xsl:stylesheet>

The correct output (containing mdash) is produced:

Hello β€” World!

Attention!

XSLT 2.0 <xsl:character-map>, , . :

<xsl:stylesheet   version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output omit-xml-declaration="yes" 
    use-character-maps="mdash"/>
  <xsl:character-map name="mdash">
    <xsl:output-character character="&#x2014;" string="&amp;mdash;" />
  </xsl:character-map>

</xsl:stylesheet>

XML ( ), :

Hello &mdash; World!
+4

, ?

. Entity XML , XSLT, , XPath. DOCTYPE .

, <xsl:output encoding="us-ascii">, ASCII, em-dash &#8212;.

XSLT 2.0 " ", , β€” &mdash; , a β€”, β€” , , &mdash;. XSLT 2.0, hack , β€” &mdash;. , , , β€” .

" ​​ ", , . HTML, Unicode, , , .

+1

Source: https://habr.com/ru/post/1743170/


All Articles