如何使用XSLT1.0一次过滤两个xml树?

如何使用XSLT1.0一次过滤两个xml树?,xml,filter,xslt-1.0,dropdown,xfa,Xml,Filter,Xslt 1.0,Dropdown,Xfa,我在寻求帮助。我有一个带有下拉菜单的XFA表单(基于XML),它保存每个项目的显示和保存值。由于列表可能很长,我尝试使用XSLT1.0对其进行过滤 下拉列表中的源XML drom可能如下所示: <?xml version="1.0" encoding="UTF-8"?> <field name="DropDownList" xmlns="http://www.xfa.org/schema/xfa-form/2.8/"> <!-- Displayed item

我在寻求帮助。我有一个带有下拉菜单的XFA表单(基于XML),它保存每个项目的显示和保存值。由于列表可能很长,我尝试使用XSLT1.0对其进行过滤

下拉列表中的源XML drom可能如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<field name="DropDownList" xmlns="http://www.xfa.org/schema/xfa-form/2.8/">
    <!-- Displayed items to be filtered --> 
    <items xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
        <text>Lorem Ipsum 0030</text>
        <text>Lorem Ipsum 0060</text>
        <text>Lorem Ipsum 0070</text>
        <text>Lorem Ipsum 0080</text>
        <text>Lorem Ipsum 0100</text>
        <text>Lorem Ipsum 0110</text>
        <text>Lorem Ipsum 0120</text>
        <text>Lorem Ipsum 0130</text>
        <text>Lorem Ipsum 0140</text>
    </items>
    <!-- Hidden save items to be filtered too -->
    <items save="1" presence="hidden" xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
        <text>item0</text>
        <text>item1</text>
        <text>item2</text>
        <text>item3</text>
        <text>item4</text>
        <text>item5</text>
        <text>item6</text>
        <text>item7</text>
        <text>item8</text>
        <text>item9</text>
    </items>
</field>

Lorem Ipsum 0030
Lorem Ipsum 0060
Lorem Ipsum 0070
Lorem Ipsum 0080
Lorem Ipsum 0100
Lorem Ipsum 0110
第0120页
Lorem Ipsum 0130
Lorem Ipsum 0140
项目0
项目1
项目2
项目3
项目4
项目5
项目6
项目7
项目8
项目9
我当前的样式表如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xfa="http://www.xfa.org/schema/xfa-form/2.8/" xml:space="preserve">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no" standalone="yes"/>
    <xsl:template match="/">
        <field name="DropDownList">
            <xsl:apply-templates/>
        </field>
    </xsl:template>
    <xsl:template match="/*[local-name()='field']/*[local-name()='items']" >
        <items xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
            <xsl:for-each select="./*[local-name()='text']">
                <xsl:if test="contains(., '01')">
                    <text>
                        <xsl:value-of select="."/>
                    </text>
                </xsl:if>
            </xsl:for-each>
        </items>
    </xsl:template>
</xsl:stylesheet>

我需要的是与以前相同的XML结构,以便将其加载回下拉列表中,但我还没有找到一种方法让第二个items树中填充正确的数据。我正在考虑使用一个参数或变量来保存第一个items树中节点的索引,并在第二个items树中查找相关节点,但是如何

<?xml version="1.0" encoding="UTF-8"?>
<field name="DropDownList" xmlns="http://www.xfa.org/schema/xfa-form/2.8/">
    <items xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
        <text>Lorem Ipsum 0100</text>
        <text>Lorem Ipsum 0110</text>
        <text>Lorem Ipsum 0120</text>
        <text>Lorem Ipsum 0130</text>
        <text>Lorem Ipsum 0140</text>
    </items>
    <items save="1" presence="hidden" xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
        <text>item5</text>
        <text>item6</text>
        <text>item7</text>
        <text>item8</text>
        <text>item9</text>
    </items>
</field>

Lorem Ipsum 0100
Lorem Ipsum 0110
第0120页
Lorem Ipsum 0130
Lorem Ipsum 0140
项目5
项目6
项目7
项目8
项目9

一种简单的方法是在模板上使用模式并应用模板。因此,将mode属性添加到apply模板。并且,将同名的mode属性添加到使用apply templates针对的模板中。然后,对于第二个输出,要么使用不同的模式,要么让它在没有模式的情况下流动。

谢谢您的输入。我已经制作了另一个样式表,它已经满足了我的需求。但是,我认为这个解决方案并不理想,因为我必须检查第一个项目树下的所有节点两次

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xfa="http://www.xfa.org/schema/xfa-form/2.8/" xml:space="preserve">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" standalone="yes"/>
    <xsl:variable name="filterText" select="01"/>
    <!--Filter display items-->
    <xsl:template match="//*[local-name()='items'][1]/*[local-name()='text']" mode="filterDisplayItems">
        <xsl:if test="contains(., $filterText)">
            <xsl:copy-of select="."/>
        </xsl:if>
    </xsl:template>
    <!--Filter save items-->
    <xsl:template match="//*[local-name()='items'][1]/*[local-name()='text']" mode="filterSaveItems">
        <xsl:param name="nodeIndex" select="position()"/>
        <xsl:if test="contains(., $filterText)">
            <xsl:copy-of select="//*[local-name()='items'][2]/*[local-name()='text'][$nodeIndex]"/>
        </xsl:if>
    </xsl:template>
    <xsl:template match="/">
        <field name="ListBackup">
            <!--Create filtered list of display items-->
            <items xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
                <xsl:apply-templates select="//*[local-name()='items'][1]/*[local-name()='text']" mode="filterDisplayItems"/>
            </items>
            <!--Create filtered list of save items-->
            <items save="1" presence="hidden" xmlns="http://www.xfa.org/schema/xfa-template/3.6/">
                <xsl:apply-templates select="//*[local-name()='items'][1]/*[local-name()='text']" mode="filterSaveItems"/>
            </items>
        </field>
    </xsl:template>
</xsl:stylesheet>

…这在我眼中造成了性能滞后。一定有更好的办法。当筛选第一个项目树的模板找到匹配项时,您可以使用…select=“position()”轻松获取其索引。这应该传递给过滤第二个项目树的模板。在那里,您只需在那里复制节点索引即可。你知道怎么处理吗