简体   繁体   English

XSLT:转换XML中使用的实体

[英]XSLT: Transform entities used in XML

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. 我在XML文件中有一个实体,并使用样式表对其进行了转换,但无法转换xml文件中使用的实体。 Browser shows the error as undefined entity. 浏览器将错误显示为未定义实体。 i want to transform it using the xslt. 我想使用xslt对其进行转换。

I Want to transform the entity &ampcopy; 我要转换实体&ampcopy;

Kindly help me on this! 请帮助我!

XML FILE: XML文件:

<article>
<main>
<content>&copy; by StactOverFlow</content>
</main>
</article>

I tried but its not working, actually i want to add it in xslt not in xml ! 我试过但是它不起作用,实际上我想在xslt中而不是在xml中添加它!

and

Browser shows the error as undefined entity. 浏览器将错误显示为未定义实体。 i want to transform it using the xslt. 我想使用xslt对其进行转换。

If your XML document contains entities like &copy; 如果您的XML文档包含&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. ,而源文档中没有这些实体的定义,那么您很不走运,因为这会使XML文档无效。

The only named entities that can be used without declaration in a DTD (either inline or referenced) are &lt; 在DTD中(内联或引用)无需声明即可使用的唯一命名实体是&lt; , &gt , &amp; &gt &amp; , &apos; &apos; and &quot; &quot; . Any other entity must either be a numerical entity reference, like &#169; 任何其他实体都必须是数字实体引用,例如&#169; , or must be defined in the DTD section. ,或必须在DTD部分中定义。

The XSLT (whether used in browser or offline) is correct in rejecting your XML input document. XSLT(无论是在浏览器中还是脱机使用)在拒绝XML输入文档方面都是正确的。 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. 如果要防止这种情况,则需要使用另一种工具来修复无效的XML,该工具不是将文档处理为XML(因为不是)而是将其处理为文本。 You can simply add the DTD definition with this preprocess, ie add lines like these in the DTD: 您可以在此预处理过程中简单地添加DTD定义,即在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). 或搜索命名的实体,然后将其替换为各自的Unicode字符或数字实体(从XML的角度来看,只要编码正确,两者之间就没有区别)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM