我可以将实体从 xml 数据传递到 xslt 样式表吗?

发布于 2024-12-19 19:40:38 字数 596 浏览 5 评论 0原文

我有十几个 xslt 模板,其中大多数使用一个特定实体(在我的示例中为“ent”)。我无法更改这些模板,但可以更改输出的 xml 数据。

问题是 - 是否可以将 xml 数据中声明的实体传递到 xslt 样式表? 我试图这样做,但失败了:

XML 文档

]>

XSL xslt.xslt

<

xsl:template match= "/">

你好:&ent;

<

/xsl:stylesheet>

I have a dozen of xslt templates and most of them using one specific entity ('ent' in my example). I'm not able to change these templates but I can change outputed xml data.

The question is - is it possible to pass entity declared in xml data to xslt stylesheets?
I am trying to make it like this, but fail:

XML document

<!DOCTYPE xsl:stylesheet [<!ENTITY ent "World">]>

<?xml-stylesheet type='text/xsl' href='xslt.xslt'?>

<doc/>

XSL xslt.xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<h1>Hello: &ent;</h1>

</xsl:template>

</xsl:stylesheet>

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

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

发布评论

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

评论(1

坏尐絯℡ 2024-12-26 19:40:39

XSLT 样式表中引用的任何实体都需要在样式表本身中分别在样式表引用的任何外部 DTD 中声明。在 XML 输入中声明实体根本没有帮助。所以答案是否定的,在 XML 文档中声明实体不允许您在稍后用于转换 XML 的 XSLT 样式表中引用此类实体。

Well any entity referenced in the XSLT stylesheet needs to be declared in the stylesheet itself respectively in any external DTD the stylesheet references. Declaring an entity in the XML input does not help at all. So the answer is no, declaring entities in an XML document does not allow you to reference such entities in an XSLT stylesheet being used later on to transform the XML.

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