XSLT does not copy the value of an HTML object

I have the following xml code:

<p>
    <media id="pc300220-scpwr.gif" print-rights="no"
        rights="licensed" type="photo">
        <title>Louis Pasteur</title>
        <credit>Granger Collection</credit>
    </media>
    <b>Louis</b> 
    <pronunciation>
        <word-term>
            <b>Pasteur</b> 
        </word-term>
    </pronunciation> (1822&ndash;1895) was a French chemist. He made major contributions
    to chemistry, medicine, and industry. His work has greatly benefited people. For
    example, he discovered that diseases spread through
    <definition>
        <word-term>bacteria </word-term>
        <word-definition>tiny living things</word-definition>
    </definition>. This discovery has saved many millions of lives.
</p>

and the following XSLT segment:

<xsl:template match="p|b|i">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

will actually generate output for example

(18221895)

But I want

(1822-1895)

So can anyone help why & ndash is not copied to the resulting XML?

+3
source share
2 answers

next segment of XSLT:

<xsl:template match="p|b|i">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

will actually generate output for example

(18221895)

But I want

(1822-1895)

I can not reproduce the problem.

With this XML document (fixed to be well-formed):

<!DOCTYPE p [
 <!ENTITY ndash   "&#8211;">
]>
<p>
    <media id="pc300220-scpwr.gif" print-rights="no"
    rights="licensed" type="photo">
        <title>Louis Pasteur</title>
        <credit>Granger Collection</credit>
    </media>
    <b>Louis</b>
    <pronunciation>
        <word-term>
            <b>Pasteur</b>
        </word-term>
    </pronunciation> (1822&ndash;1895) was a French chemist. He made major contributions         to chemistry, medicine, and industry. His work has greatly benefited people. For         example, he discovered that diseases spread through
    <definition>
        <word-term>bacteria </word-term>
        <word-definition>tiny living things</word-definition>
    </definition>. This discovery has saved many millions of lives.
</p>

, and when this conversion is applied :

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

    <xsl:template match="p|b|i">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

result :

    Louis Pasteur
    Granger Collection

<b>Louis</b>


        <b>Pasteur</b>

 (1822–1895) was a French chemist. He made major contributions         to chemistry, medicine, and industry. His work has greatly benefited people. For         example, he discovered that diseases spread through

    bacteria 
    tiny living things
. This discovery has saved many millions of lives.

+3
source

Demetrius was right in saying that there are no problems in the XSLT code. However, this is not an XSLT problem, it is a parsing problem.

&ndash;, XML. , . , XML , DTD, &ndash;. DTD XML- (, Dimitre) DTD, XML. DTD, , , DTD .

,

, , .

XML 1.0: (ref: http://www.w3.org/TR/xml/#wf-entdeclared)

, , ; , , = ''.

: (ref: http://www.w3.org/TR/xml/#include-if-valid)

, XML, , , . , , , .

, , , , . 1822&ndash;1895 18221895. XSLT , , XSLT- XML.

, DTD, , , , .

+2

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


All Articles