代码之家  ›  专栏  ›  技术社区  ›  Hobbes

多输出文档:我可以从结果文档引用到原始文档吗?

  •  0
  • Hobbes  · 技术社区  · 6 年前

    基本上,我有两个目录, in out 我使用XSLT在目录中创建文件 在里面

    <file name="1 old.xml"><...></file>
    <file name="2 new.xml"><...></file>
    

    包含 <source> <target>

    <xsl:template match="file">
        <xsl:result-document method="xml" href="{outputfolder\@name}">
        <xsl:when test="unparsed-text-available(inputfolder\@name)">
            <xsl:apply-templates select="document(inputfolder\@name)"/>
        </xsl:when>
    </xsl:template>
    

    在里面

    • 如果文件名包含“old”,我想修改“1 old.xml”中的一个节点。

    <xsl:template match="target">
        <xsl:choose>
             <xsl:when test="...">
                 <xsl:copy>
                     <xsl:copy-of select="ancestor::*/source"/>
                 </xsl:copy>    
             </xsl:when>
             <xsl:otherwise>
                <xsl:apply-templates/>
             </xsl:otherwise>
    </xsl:template>
    

    在此模板中,当前节点是 < 1 old.xml filelist.xml 创建了我的输出文档?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Michael Kay    6 年前

    最简单的方法是将全局变量绑定到主输入文档:

    <xsl:variable name="filelist" select="/" as="document-node(element(file))"/>
    

    $filelist .

    as