如何在 XSLT 中处理 HTML 实体 nbsp.不改变输入文件 [英] How to handle HTML entity nbsp in XSLT. Without changing the input file

查看:31
本文介绍了如何在 XSLT 中处理 HTML 实体 nbsp.不改变输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 XSLT(使用 Oxygen 9.0 进行转换)将 HTML 文件转换为 XML 文件.

当我使用 HTML 文件配置和运行 XSLT 转换时,氧气输出

实体nbsp"已被引用,但未声明.

我的输入 html 文件是:

<div><span>&nbsp;一些文字</span></div>

注意:我想知道如何仅使用 XSLT 处理该实体,我不想对输入文件进行任何更改.

解决方案

您可以使用 XML 实体来创建定义 nbsp 实体的 XML 文件,并包含(损坏的)XML片段.

例如,假设您的片段保存为名为:invalid.xml"

<div><span>&nbsp;一些文字</span></div>

像这样创建一个 XML 文件:

当该文件被解析时,它将定义 nbsp 实体,包括invalid.xml"中的内容,并正确解析 nbsp 实体.结果是这样的:

<div><跨度>一些文字</span>

</包装器>

然后,只需调整您的 XSLT 以适应新的文档元素(在本例中为元素 ).

I am trying to convert an HTML file into XML file using XSLT (Using Oxygen 9.0 for transformation).

When I configure and run the XSLT transformation with the HTML file then Oxygen outputs

The entity 'nbsp' was referenced,but not declared.

My input html file is:

<div><span>&nbsp;some text</span></div>

Note: I want to know how handle that entity only using the XSLT, I don't want to make any changes to the input file.

解决方案

You could use XML Entities to create an XML file that defines the nbsp entity, and includes the (broken) XML fragment.

For example, assume that your fragment is saved as a file called: "invalid.xml"

<div><span>&nbsp;some text</span></div>

Create an XML file like this:

<!DOCTYPE wrapper [
   <!ENTITY nbsp "&#160;">
   <!ENTITY invalid-xml-document SYSTEM "./invalid.xml">
]><wrapper>
&invalid-xml-document;</wrapper>

When it that file gets parsed, it will have defined the nbsp entity, include the content from the "invalid.xml", and resolve the nbsp entity properly. The result is this:

<wrapper>
  <div>
    <span> some text</span> 
  </div>
</wrapper>

Then, just adjust your XSLT to accomodate the new document element (in this example the element <wrapper>).

这篇关于如何在 XSLT 中处理 HTML 实体 nbsp.不改变输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆