【问题标题】:value-of select="document($path)/ns0:element1/ns0:element2" returns NULL with SAXON-B XSLT 2.0 (saxon9)value-of select="document($path)/ns0:element1/ns0:element2" 使用 SAXON-B XSLT 2.0 (saxon9) 返回 NULL
【发布时间】:2014-03-13 22:33:11
【问题描述】:

下面的 getdetails.xslt 代码 (XSLT 2.0) 通过 document() 读取 user-config.xml 的内容。

代码在 Saxon 9.4.0.6 上成功运行,并且 ns0:project_abs_path 的值在 xml 输出中可见,如下所示

<?xml version = "1.0" encoding = "UTF-8"?>
<xmlString>&lt;?xml version="1.0" encoding="UTF-8"?> C:\myProject</xmlString>

但是,当在 TIBCO 转换活动中针对 SAXON-B XSLT 2.0 (saxon9) 运行相同的 XSLT 代码时,将返回以下 xml 输出(注意:ns0:project_abs_path 没有值)。

<?xml version = "1.0" encoding = "UTF-8"?>
<xmlString>&lt;?xml version="1.0" encoding="UTF-8"?></xmlString>

*没有返回错误。

user-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<ns0:userRules xmlns:ns0="http://www.tibco.com/schemas/-bw/SharedResources/Schema.xsd">
    <ns0:project_abs_path>C:\myProject1</ns0:project_abs_path>
</ns0:userRules>

getdetails.xslt

<?xml version='1.0'?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.tibco.com/schemas/bw/SharedResources/Schema.xsd" 
xmlns:ns1="http://www.tibco.com/schemas/bw/SharedResources/rule-db.xsd">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:param name="invar_ruleid"/>
<xsl:variable name="var_installation_path">C:\FOLDER</xsl:variable>
<xsl:variable name="var_user_config_path" select="concat($var_installation_path,'\bin\user-config.xml')"/>
<xsl:variable name="var_project_abs_path" select="document($var_user_config_path)/ns0:userRules/ns0:project_abs_path"/>
<xsl:variable name="file">file:///</xsl:variable>
<xsl:variable name="var_out_file_path" select="concat($file,$var_project_abs_path)"/>
<xsl:template match="/">
<xsl:value-of select="document(concat($var_installation_path,'\bin\user-config.xml'))/ns0:userRules/ns0:project_abs_path"/> 
</xsl:template>
</xsl:stylesheet>

【问题讨论】:

    标签: xml xslt-2.0 saxon


    【解决方案1】:

    说“返回 NULL”是非常含糊的。你能更明确一点吗?您是否看到异常、Saxon 错误消息或不正确的转换结果?如果你看到一个异常,你能显示堆栈跟踪吗?如果您看到撒克逊错误消息,您能告诉我们它是什么吗?

    您的代码唯一明显错误的是您正在构建一个 Windows 文件名(格式为“c:\a\b\c”)并将其传递给需要 URI 的 document() 函数。从理论上讲,这总是错误的,但有些应用程序可以容忍它。您应该传递格式为“file:///c:/a/b/c”的 URI。我不知道这是否是问题的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多