The entity “nbsp” was referenced, but not declared

2019-06-02 06:29发布

问题:

I have written one XSLT to transform xml to xml.

Input XML:

<test>The Spanish word for "Spain" is "Espa&nbsp;a" Dagon his Name, Sea Monster</test>

OutputXML:

<test>The Spanish word for "Spain" is "Espa a" Dagon his Name, Sea Monster</test>

XSL FILE: i have added the code for entity nbsp declaration under doctype at and replace with   entity but still are same error The entity "nbsp" was referenced, but not declared.

<xsl:template match="test">
<test>
  <xsl:apply-templates/>
</test>

回答1:

You need to have the input declare the entities it uses, as done in http://xsltransform.net/gVhD8QR with e.g.

<!DOCTYPE test [
  <!ENTITY nbsp "&#160;">
]>
<test>The Spanish word for "Spain" is "Espa&nbsp;a" Dagon his Name, Sea Monster</test>

Note that the Spanish word for "Spain" is "España" however, so the example entity used there does not make sense there anyway.



回答2:

You can escape the nbsp like this:

UPDATE try this:

<xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;

So you final code will look like:

<test>The Spanish word for "Spain" is "Espa<xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;a" Dagon his Name, Sea Monster</test>

If all else fails use this which is sure to work:

&#160;

Cheers