3

入力 XML ファイルで相対パスが指定されている XML ファイルをマージ (およびメタ情報を追加) しようとしています。マージしたいファイルは「files」というサブディレクトリにあります入力ファイルの構造は次のとおりです

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

firstfile.xml と secondfile.xml の構造は次のとおりです。

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

1 つのファイルのすべてのテーブル ノードをグループに入れ、それにメタ情報を追加したいと考えています。そこで、次の XSLT スタイルシートを作成しました。

   <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>

すべてのファイルについて、エラーが発生します。

指定されたファイルが見つかりませんでした。

空のノード セットが返されたことを示しています (そのため、ファイルをロードできませんでした)。この問題を解決する方法を知っている人はいますか?

乾杯

4

2 に答える 2

1

document() 関数の引数は文字列でなければなりません。変数のパスのノード値を ./ と連結して取得し、それを渡します。コンピューターに到達したら簡単なテストを行うことができますが、それはあなたの問題だと思います。ここにオプションがあります:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
    <tables>
        <xsl:apply-templates/>
    </tables>
</xsl:template>
<xsl:template match = "file">
    <xsl:variable name="filepath" select="concat('./',path)"/>
    <xsl:call-template name="tableprocessor">
        <xsl:with-param name="tables" select="document($filepath)/tables"/>
    </xsl:call-template>   
</xsl:template>
<xsl:template name="tableprocessor">
    <xsl:param name="tables"/>
    <group>
        <xsl:copy-of select="$tables"/>
    </group>
</xsl:template>
</xsl:stylesheet>
于 2013-08-27T15:32:04.783 に答える