如何将 XML 中的上标/下标转换为 HTML
我有以下 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-&#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)"/>
目前,当我应用 XSLT 时,输出如下所示。
我们展示了核天体物理学中使用的不同模型。特别强调了微观集群理论的作用。最近的三重应用程序α过程,并在 12C(α, γ)16O 和 3He( α,γ )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-α 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)"/>
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,无论是谁生成了此标记,都将标记放入了属性中。这有效地破坏了所有标记,结果只是属性内的一维文本。
这确实是一种邪恶的做法。为了能够使用 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.