Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何编写递归包含其他文件的XSLT?_Xml_Xslt_Recursion_File Inclusion - Fatal编程技术网

Xml 如何编写递归包含其他文件的XSLT?

Xml 如何编写递归包含其他文件的XSLT?,xml,xslt,recursion,file-inclusion,Xml,Xslt,Recursion,File Inclusion,假设我有一系列这种格式的xml文件: A.xml: 但是我如何使它也变成这样呢 <h1> Page B </h1> <p> Blah Blah Blah </p> <p> blAh blAh blAh </p> B页 废话连篇 废话废话 我知道我需要在某个地方使用文档(concat(@还包括,'.xml')),但我不确定在哪里 哦,关键是,如果B被包含在第三个文件中,C.xml,我需要

假设我有一系列这种格式的xml文件:

A.xml: 但是我如何使它也变成这样呢

<h1>
    Page B
</h1>
<p>
    Blah Blah Blah
</p>
<p>
    blAh blAh blAh
</p>

B页

废话连篇

废话废话

我知道我需要在某个地方使用
文档(concat(@还包括,'.xml'))
,但我不确定在哪里


哦,关键是,如果B被包含在第三个文件中,
C.xml
,我需要这个方法仍然有效

有什么办法吗?

有可能:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="page">
    <h1>
      <xsl:value-of select="header"/>
    </h1>
    <p>
      <xsl:apply-templates select="." mode="content"/>
    </p>
  </xsl:template>

  <xsl:template match="page" mode="content">
    <xsl:value-of select="content"/>
    <xsl:if test="@include">
      <xsl:apply-templates select="document(@include)" mode="content"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>



我怀疑您不能完全用XSL完成这项工作,但我倾向于提出这个问题,看看我是否错了。我认为使用递归模板应该是可能的。我认为
模式
属性可能就是我想要的。让我在我的场景中测试一下,好吧,这个推力还不够大。我的例子过于简化了。你们能看一看更难的问题吗?
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/page">
        <h1>
            <xsl:value-of select="header" />
        </h1>
        <p>
            <xsl:value-of select="content" />
        </p>
    </xsl:template>
</xsl:stylesheet>
<h1>
    Page A
</h1>
<p>
    blAh blAh blAh
</p>
<h1>
    Page B
</h1>
<p>
    Blah Blah Blah
</p>
<p>
    blAh blAh blAh
</p>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="page">
    <h1>
      <xsl:value-of select="header"/>
    </h1>
    <p>
      <xsl:apply-templates select="." mode="content"/>
    </p>
  </xsl:template>

  <xsl:template match="page" mode="content">
    <xsl:value-of select="content"/>
    <xsl:if test="@include">
      <xsl:apply-templates select="document(@include)" mode="content"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>