XSL conversion and special XML objects,

I have an XML file that is converted using XSL. Some elements need to be changed, some of them should be left as it is, in particular, text objects , and , and , and ;, amos , < , and should be left as it is, and in my case " and & are changed to ' and ' .

XML testing:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <element>
        &quot;
        &amp;
        &apos;
        &lt;
        &gt;
    </element>
</root>

conversion file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no" indent="no" />
    <xsl:template match="element">
        <xsl:copy>
            <xsl:value-of disable-output-escaping="no" select="." />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

result:

<?xml version="1.0" encoding="UTF-8"?>
    <element>
        "
        &amp;
        '
        &lt;
        &gt;
    </element>

desired result:

<?xml version="1.0" encoding="UTF-8"?>
    <element>
        &quot;
        &amp;
        &apos;
        &lt;
        &gt;
    </element>

I have 2 questions:

  • why are some of these objects converted and others not?
  • How can I get the desired result?
+3
2

, <, > & XML. XML, , ( ).

, ' ", , XML ( , , :

<xml ackbar="He said, &quot;It a trap!&quot;" />
<xml ackbar='He said, "It&apos;s a trap!"' />

, , .

- (, DOM) , , XML .

, ( , &#10;) - .

, XML (, DOM-), . . , XML (, ), .; -)

+3

, ,

&amp;quot;
0

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


All Articles