XSLT 文档('')函数不起作用 [英] XSLT document('') function doesn't work

查看:24
本文介绍了XSLT 文档('')函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从文档中了解到,以空字符串为参数的 XSLT 函数 document() 应该读取当前的 XSLT 文档.但以下代码不起作用:

As I understand from docs, XSLT function document() with empty string as parameter should read current XSLT document. But the following code doesn't work:

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <state>test2</state>
   <xsl:template match="/">
      test1
      <xsl:value-of select="document('')/*/state"/>
    </xsl:template>
   </xsl:stylesheet>

当我将此 XSLT 应用于某些 XML(仅作为示例)时,我只有test1"作为输出.为什么要排队

When I apply this XSLT to some XML (just for example), I have only "test1" as output. Why line

 <xsl:value-of select="document('')/*/state"/>

不打印test2"?

推荐答案

document('') 的定义是它读取 URI 与包含该文档的样式表中指令的基 URI 相同的 XML 文档('') 称呼.除非您使用外部实体,否则这通常与样式表模块的基本 URI 相同.如果它不起作用,这通常是因为样式表模块的基本 URI 未知.如果 XSLT 处理器获得内存中的样式表(例如作为字符串或 DOM)而不是通过 URI 检索的资源,则很容易发生这种情况.例如,如果您使用 JAXP StreamSource 并且不调用 setSystemId(),则基本 URI 将是未知的.

The definition of document('') is that it reads the XML document whose URI is the same as the base URI of the instruction in the stylesheet containing the document('') call. Unless you use external entities, this is normally the same as the base URI of the stylesheet module. If it doesn't work, this is often because the base URI of the stylesheet module is unknown. This can easily happen if the XSLT processor is given a stylesheet that's in memory (for example as a character string or a DOM) rather than a resource retrieved via a URI. For example, if you use a JAXP StreamSource and don't call setSystemId() then the base URI will be unknown.

这篇关于XSLT 文档('')函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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