我有以下 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–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 "–">
]>
<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–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/