如何将 XML 中的上标/下标转换为 HTML

发布于 2024-12-03 21:41:57 字数 882 浏览 2 评论 0原文

我有以下 XML 片段,其中的公式作为其他文本的一部分。 XSLT 将其转换为 HTML。最终的 HTML 输出应反映所应用的上标。实现这一目标的正确方法是什么?

XML 片段生成如下。

<meta name="Abstract" content="We present different models used in nuclear astrophysics. In particular the role of microscopic cluster theories is emphasized. Recent applications on the triple-&amp;#945; process, and on the &lt;sup&gt;12&lt;/sup&gt;C(&amp;#945;, &amp;#947;)&lt;sup&gt;16&lt;/sup&gt;O and &lt;sup&gt;3&lt;/sup&gt;He(&amp;#945;, &amp;#947; )&lt;sup&gt;7&lt;/sup&gt;Be reactions are discussed. (author)"/>

目前,当我应用 XSLT 时,输出如下所示。

我们展示了核天体物理学中使用的不同模型。特别强调了微观集群理论的作用。最近的三重应用程序&#945;过程,并在 12C(&#945;, &#947;)16O 和 3He( &#945;,&#947; )7讨论了Be反应。 (作者)

任何帮助表示赞赏。

I have the following XML snippet with formulas as part of some other text. This is being transformed to HTML by an XSLT. The final HTML output should reflect the superscript applied. What is the right approach to achieve this?

The XML snippet is generated as below

<meta name="Abstract" content="We present different models used in nuclear astrophysics. In particular the role of microscopic cluster theories is emphasized. Recent applications on the triple-&#945; process, and on the <sup>12</sup>C(&#945;, &#947;)<sup>16</sup>O and <sup>3</sup>He(&#945;, &#947; )<sup>7</sup>Be reactions are discussed. (author)"/>

Currently, when I apply the XSLT, the output is as below

We present different models used in nuclear astrophysics. In particular the role of microscopic cluster theories is emphasized. Recent applications on the triple-α process, and on the <sup>12</sup>C(α, γ)<sup>16</sup>O and <sup>3</sup>He(α, γ )<sup>7</sup>Be reactions are discussed. (author)

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2024-12-10 21:41:57

问题在于,无论是谁生成了此标记,都将标记放入了属性中。这有效地破坏了所有标记,结果只是属性内的一维文本。

这确实是一种邪恶的做法。为了能够使用 XPath 和 XSLT 将字符串作为标记进行处理,需要从字符串重新构建标记。您需要一个预处理步骤来将 content 属性的内容解析为新的 XmlDocument,或者您可以在 XSLT 代码中调用扩展函数(您需要编写),该函数将解析文本并返回文档节点。

在 XSLT 3.0 / XPath 3.0 中,将有一个标准函数 parse-xml() 正是针对这样的情况。

The problem is that whoever generated this put markup inside an attribute. This effectively destroys all markup and the result is just a 1-dimensional text inside the attribute.

This is an evil practice, indeed. To be able to process the string as markup -- using XPath and XSLT -- the markup needs to be re-constituted from the string. You need to have either a pre-processing step to parse the content of the content attribute as a new XmlDocument, or you could call an extension function (that you need to write) within the XSLT code, that would parse the text and return a document node.

In XSLT 3.0 / XPath 3.0 there will be a standard function parse-xml() exactly for cases like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文