Jatin Gadhiya
Jatin Gadhiya

Reputation: 2075

Parsing XML with “&” and “®” using XSLT but still getting errors

I want to decode HTML tags from a string and used:

disable-output-escaping="yes"

That was working properly until the string contained ® (meaning ®).

Then I found that a possible solution is to replace ® with ®; but it is not working.

i am using this code

   <xsl:if test="$ShortDescription !=''">
          <shortdescription><xsl:value-of  select="replace($ShortDescription,'&reg;','&#174;')"  disable-output-escaping="yes"/></shortdescription>
   </xsl:if>

The XSLT file giving me the error looks like this:

HTTP Status 500 - {msg=getTransformer fails in getContentType,trace=java.lang.RuntimeException: getTransformer fails in getContentType at 

and when i am not used replace function then its give error look like: XML Parsing Error: undefined entity at

<shortdescription>Wear some adventure with the same hat Indiana Jones&reg; wears in his movies.</shortdescription>

Upvotes: 0

Views: 905

Answers (1)

Michael Kay
Michael Kay

Reputation: 163595

If the input file contains the entity reference &reg; and contains no entity definition for this entity, then it's not well-formed XML which means you can't process it using XSLT. Possible solutions include:

  • add a definition of this entity by including an appropriate DTD
  • replace &reg; by &#174; using non-XML technology before parsing, e.g. sed/awk/Perl
  • use an HTML parser rather than an XML parser, e.g. validator.nu.

Upvotes: 1

Related Questions