1
votes

I have a entities in my XML file, and using a stylesheet to transform it, but unable to transform the entities used in the xml file. Browser shows the error as undefined entity. i want to transform it using the xslt.

I Want to transform the entity &ampcopy;

Kindly help me on this!

XML FILE:

<article>
<main>
<content>&copy; by StactOverFlow</content>
</main>
</article>
1
Your answer may be found here? stackoverflow.com/questions/6508860/…Luke
I tried but its not working, actually i want to add it in xslt not in xml !dasanb
What'd you try? Replacing &copy; with &#169;, or defining the entities in the doctype?Luke
defined the entities in doctype like this <!DOCTYPE article PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY copy "copy"> ] >dasanb
May need to be <!ENTITY copy "&#169;">.Luke

1 Answers

2
votes

I tried but its not working, actually i want to add it in xslt not in xml !

and

Browser shows the error as undefined entity. i want to transform it using the xslt.

If your XML document contains entities like &copy;, and the definition of these entities is not available from the source document, then you are out of luck, because this makes your XML document invalid.

The only named entities that can be used without declaration in a DTD (either inline or referenced) are &lt;, &gt, &amp;, &apos; and &quot;. Any other entity must either be a numerical entity reference, like &#169;, or must be defined in the DTD section.

The XSLT (whether used in browser or offline) is correct in rejecting your XML input document. If you want to prevent this, you will need to fix your invalid XML with another tool, one that processes the document not as XML (because it isn't) but as text. You can simply add the DTD definition with this preprocess, i.e. add lines like these in the DTD:

<!ENTITY copy "&#169;">

or search for the named entities and replace them for their respective Unicode characters or the numeric entities (from an XML standpoint, there is no difference between the two, as long as the encoding is correct).