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/Xpath:使用冗余Xpath启动器匹配多个元素_Xml_Xslt_Xpath - Fatal编程技术网

Xml XSLT/Xpath:使用冗余Xpath启动器匹配多个元素

Xml XSLT/Xpath:使用冗余Xpath启动器匹配多个元素,xml,xslt,xpath,Xml,Xslt,Xpath,我有一个如下所示的XML: <parent> <child1/> <child2/> <child3/> <child4/> <child5/> <child6/> </parent> <xsl:template match="parent/child1|parent/child4|parent/child6/> 我有一个模板,只匹配

我有一个如下所示的XML:

<parent>
    <child1/>
    <child2/>
    <child3/>
    <child4/>
    <child5/>
    <child6/>
</parent>
<xsl:template match="parent/child1|parent/child4|parent/child6/>

我有一个模板,只匹配特定的子对象,如下所示:

<parent>
    <child1/>
    <child2/>
    <child3/>
    <child4/>
    <child5/>
    <child6/>
</parent>
<xsl:template match="parent/child1|parent/child4|parent/child6/>
您可以试试

<xsl:template match="parent/*[self::child1 or self::child4 or self::child6]"/>

在这个特定示例中,您可以编写以下内容

 <xsl:template match="child1|child4|child6"/>

编辑:如注释中所述,这只适用于XSLT 3.0及以上版本。

在XPath 2.0
parent/(child1 | child4 | child6)
中,这将完全满足您的需要。在XPath 1.0中-此语法是不可接受的语法将在
select
语句中工作,但在只需要“模式”(这只是XPath表达式的子集。请参阅)的模板匹配中不起作用。我认为您的建议是XSLT 3支持
,但XSLT 1和XSLT 2不支持。谢谢Martin。我曾在测试时测试过它,但将处理器保留为Saxon 9.5.1,这给人的印象是它在XSLT1.0中工作。。。。