【问题标题】:insert <?xml-stylesheet tag with xsl使用 xsl 插入 <?xml-stylesheet 标记
【发布时间】:2010-11-21 00:10:28
【问题描述】:

如何使用 XSLT 添加样式表引用?

我正在尝试使用第一个转换去除一些大型输入 XML,并且需要在客户端上应用第二个转换。因此第一个变换必须输出正确的参考,例如:

<?xml-stylesheet type="text/xsl" href="client.xsl"?>

回顾一下它是 XML->transform1(server)->XML->transform2(client)->HTML

到目前为止,我可以使它工作的唯一方法是使用 xsl:text disable-output-escaping 和 CDATA:

&lt;xsl:text disable-output-escaping="yes"&gt;&lt;![CDATA[&lt;?xml-stylesheet type="text/xsl" href="/efo/efo_class.xsl"?&gt;]]&gt;

肯定有更好的方法。

【问题讨论】:

标签: xml xslt


【解决方案1】:

基于 XSLT 规范,Creating Processing Instructions

<xsl:processing-instruction name="xml-stylesheet">
  <xsl:text>type="text/xsl" href="client.xsl"</xsl:text>
</xsl:processing-instruction>

将创建处理指令:

<?xml-stylesheet type="text/xsl" href="client.xsl"?>

【讨论】:

  • +1 - 我可能会将值包装在 &lt;xsl:text&gt; 中并添加换行符以提高可读性。
  • 好主意,已编辑。您应该在规范中编写示例:)
  • @Tomalak 当然,但我不想遇到这个问题只是为了得到部分答案:P
  • 如果我把它放在 XSL 中,我会得到错误:元素 is not allowed as child of element
  • @Christoffer 我还必须弄清楚将它放在哪里......它在&lt;xsl:template&gt;内部工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-07
  • 2013-12-16
相关资源
最近更新 更多