XSLT 打开其他 xml 文件 [英] XSLT open other xml files

查看:26
本文介绍了XSLT 打开其他 xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将合并其相对路径在我的输入 XML 文件中指定的 XML 文件(并添加元信息).我要合并的文件位于名为files"的子目录中输入文件的结构如下

I am about to merge XML files (and adding meta information) whose relative path is specified in my input XML file. The files I want to merge are located in a subdirectory called "files" The structure of the input file is the following

<files>
   <file>
       <path>files/firstfile.xml</path>
   </file>
   <file>
       <path>files/secondfile.xml</path>
   </file>
</files>

firstfile.xml 和 secondfile.xml 的结构如下

The firstfile.xml and secondfile.xml have the following structure

    <tables>
        <table name = "...">
        ...
        </table>
        ...
    <tables>

我想将一个文件的所有表节点放在一个组中,并向其添加元信息.所以我写了下面的 XSLT 样式表:

I would like to put all table nodes of one file in a group and add meta information to it. So I wrote the following XSLT stylesheet:

   <xsl:template match="/">
    <tables>
          <xsl:apply-templates/>
    </tables>
</xsl:template>


<xsl:template name = "enrichWithMetaInformation" match = "file">
            <xsl:apply-templates select="document(./path)/tables">
                <xsl:with-param name="file" select="."/>
            </xsl:apply-templates>


</xsl:template>

<xsl:template match="tables">

    <group>
        <meta>
            ...Some meta data ...
        </meta>
        <xsl:copy-of select="./table"/>
    </group>
</xsl:template>

对于每个文件,我都会收到一个错误:

For every file I get an error:

系统找不到指定的文件.

The system could not find the file specified.

它指出已返回一个空节点集(因此无法加载文件).有人知道如何解决这个问题吗?

It states that an empty node set has been returned (so the file could not be loaded). Does anybody have an idea of how to fix this issue?

干杯

推荐答案

检查源文档的基 URI 是否已知,例如通过执行 base-uri(/).在参数作为节点(或节点集)提供的情况下,此值用于解析传递给 document() 的相对 URI.

Check that the base URI of the source document is known, for example by doing base-uri(/). This value is used for resolving the relative URI passed to document(), in the case where the argument is supplied as a node (or set of nodes).

基本 URI 未知的两种常见情况是:

Two common situations where the base URI is unknown are:

(a) 如果您将源文档作为内存中的 DOM 提供

(a) if you supply the source document as an in-memory DOM

(b) 如果您提供源文档作为输入流或没有已知 URI 的 Reader.

(b) if you supply the source document as an input stream or Reader with no known URI.

这篇关于XSLT 打开其他 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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