我的理解是,尽管 XSLT 的“节点集”被称为“集”,但它们实际上是节点的有序列表(这就是每个节点与索引相关联的原因)。因此,我一直在尝试使用“|” 运算符连接节点集,以便遵守节点的顺序。
我试图完成的是类似于下面的 JavaScript 代码:
[o1,o2,o3].concat([o4,o5,o6])
产生:
[o1,o2,o3,o4,o5,o6]
但是,请考虑以下简化示例:
测试扁平化.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="parentTransition" select="//*[@id='parentTransition']"/>
<xsl:variable name="childTransition" select="//*[@id='childTransition']"/>
<xsl:variable name="parentThenChildTransitions" select="$parentTransition | $childTransition"/>
<xsl:variable name="childThenParentTransitions" select="$childTransition | $parentTransition"/>
<return>
<parentThenChildTransitions>
<xsl:copy-of select="$parentThenChildTransitions"/>
</parentThenChildTransitions>
<childThenParentTransitions>
<xsl:copy-of select="$childThenParentTransitions"/>
</childThenParentTransitions>
</return>
</xsl:template>
</xsl:stylesheet>
给定以下输入:
<?xml version="1.0"?>
<root>
<element id="parentTransition"/>
<element id="childTransition"/>
</root>
产生(使用xsltproc):
<?xml version="1.0"?>
<return>
<parentThenChildTransitions>
<element id="parentTransition"/><element id="childTransition"/>
</parentThenChildTransitions>
<childThenParentTransitions>
<element id="parentTransition"/><element id="childTransition"/>
</childThenParentTransitions>
</return>
所以“|” 运算符实际上不尊重节点集操作数的顺序。有没有办法可以连接节点集以尊重顺序?