xml - XSLT 不复制 HTML 实体的值

标签 xml xslt xml-parsing

我有以下 xml 代码:

<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>

和以下 XSLT 段:

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

实际上会生成类似的输出

(18221895)

但是我想要

(1822-1895)

那么有人可以帮助解释为什么没有将 &ndash 复制到生成的 XML 中吗?

最佳答案

the following XSLT segment:

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

will actually generate the output like

(18221895)

But I want

(1822-1895)

我无法重现问题。

使用此 XML 文档(已更正以确保格式正确):

<!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>

以及应用此转换时:

<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>

结果是:

    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.

关于xml - XSLT 不复制 HTML 实体的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5034225/

相关文章:

android - Android XML 可以输入 "@"吗?

java 使用 getResource() 从相对路径读取 xml 文件

java - xml dom解析器在java中按名称查找标签

XML 到 CSV 在第一个值的开头使用 XSLT 换行和空格

java - 在 XSLT 中调用 Java 方法

php - 如何确保文件是 XML 文件

java - 使用 XMLPullParser 解析 XML 时出现异常

android - 膨胀类 android.support.v7.widget.SearchView 时出错

html - xslt: css 在 html 页面中不工作

ios - 如何在Objective C中使用XML解析发布具有特殊字符和泰语的字符串?