Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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 包括XSL模板和合并输出_Xml_Xslt - Fatal编程技术网

Xml 包括XSL模板和合并输出

Xml 包括XSL模板和合并输出,xml,xslt,Xml,Xslt,我有两个xsl样式表,它们都转换元素: 输出应该合并,但被main.xslt或include.xslt覆盖。(取决于订单) 我不希望修改include.xslt文件,因为它是在其他样式表之间共享的,不应该修改 main.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:includ

我有两个xsl样式表,它们都转换元素

输出应该合并,但被
main.xslt
include.xslt
覆盖。(取决于订单)

我不希望修改
include.xslt
文件,因为它是在其他样式表之间共享的,不应该修改

main.xslt

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

  <xsl:include href="include.xslt"/>
  <xsl:template match="Group[@id='all']">
    <xsl:copy>
      <xsl:copy-of select="@*|node()" />
      <xsl:apply-templates select="document('part1.xml')" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

include.xslt

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

  <xsl:template match="Group[@id='all']">
    <xsl:copy>
      <xsl:copy-of select="@*|node()" />
      <xsl:apply-templates select="document('part2.xml')" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

input.xml

<?xml version="1.0"?>

<Group id="all">
testdata below:
</Group>

测试数据如下:
第1.xml部分

<?xml version="1.0"?>
<data id="test1">
Here is some test data.
</data>

这是一些测试数据。
第2.xml部分

<?xml version="1.0"?>
<data id="test2">
Here is some more data.
</data>

这里还有一些数据。
实际产量:

<?xml version="1.0"?>
<Group id="all">
testdata below:

Here is some test data.
</Group>

测试数据如下:
这是一些测试数据。
预期产出:

<?xml version="1.0"?>
<Group id="all">
testdata below:

Here is some test data.
Here is some more data.
</Group>

测试数据如下:
这是一些测试数据。
这里还有一些数据。

通常的方法是使用
xsl:import
而不是
xsl:include
,然后添加
xsl:apply imports

main.xslt

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="include.xslt"/>
  <xsl:template match="Group[@id='all']">
    <xsl:copy>
      <xsl:copy-of select="@*|node()" />
      <xsl:apply-templates select="document('part1.xml')" />
      <xsl:apply-imports/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
因此,根据我所见,您需要(选择一个):

  • 第二次处理输出以实际合并两个
    元素
  • 使用扩展函数如(或使用XSLT 2.0)将
    结构保存在变量中,然后处理该变量以合并
    s
  • 修改
    include.xslt
    ,使其不输出
    Group
    (或下面的文本
    testdata:

感谢您的回答,不幸的是,使用导入将不起作用,因为包含的文件中还有其他模板,这些模板都需要在
main.xslt
中指定。您有使用node-set()的示例吗?我使用节点集解决了它,稍后将发布解决方案
<Group id="all">
testdata below:

Here is some test data.
<Group id="all">
testdata below:

Here is some more data.
</Group></Group>