Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
XSLT foreach循环_Xslt_Variables_Foreach - Fatal编程技术网

XSLT foreach循环

XSLT foreach循环,xslt,variables,foreach,Xslt,Variables,Foreach,在过去的几周里,我才开始学习xslt和xml,我迫切需要一些帮助来编写一些代码来实现我想要实现的目标。 我有以下xml: <?xml version="1.0" encoding="UTF-8"?> <abc1 formName="Form"> <Level1> <Element1>ZZZ</Element1> <Element2> <SubElement

在过去的几周里,我才开始学习xslt和xml,我迫切需要一些帮助来编写一些代码来实现我想要实现的目标。 我有以下xml:

<?xml version="1.0" encoding="UTF-8"?>
<abc1 formName="Form">
    <Level1>
        <Element1>ZZZ</Element1>
        <Element2>
            <SubElement1>Apples</SubElement1>
            <SubElement2>Oranges</SubElement2>
            <SubElement3>Pears</SubElement3>
            <SubElement4>Blueberries</SubElement4>
            <SubElement5>Milkshakes</SubElement5>
        </Element2>
    </Level1>
    <Level1>
        <Element1>XXX</Element1>
        <Element2>
            <SubElement1>Apples</SubElement1>
            <SubElement2>Oranges</SubElement2>
            <SubElement3>Kiwifruit</SubElement3>
            <SubElement4>Blueberries</SubElement4>
            <SubElement5>Soda</SubElement5>
        </Element2>
    </Level1>
</abc1>
        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
因此,如果整个xml中只有一个潜在值,则单元格中的值应如上所示。如果两个元素1的值不同,则单元格应在每个单元格中列出上述值,并用逗号分隔

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
关于cell_j,我会尽量解释得更好一些

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
首先,我需要确定整个xml中的
值是否相同。在这种情况下不是,一部分是奶昔,另一部分是苏打水。因此,单元格J应包含文本“奶昔、苏打”

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
如果xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
    <abc1 formName="Form">
        <Level1>
            <Element1>ZZZ</Element1>
            <Element2>
                <SubElement1>Apples</SubElement1>
                <SubElement2>Oranges</SubElement2>
                <SubElement3>Pears</SubElement3>
                <SubElement4>Blueberries</SubElement4>
                <SubElement5>Milkshakes</SubElement5>
            </Element2>
        </Level1>
        <Level1>
            <Element1>XXX</Element1>
            <Element2>
                <SubElement1>Apples</SubElement1>
                <SubElement2>Oranges</SubElement2>
                <SubElement3>Kiwifruit</SubElement3>
                <SubElement4>Blueberries</SubElement4>
                <SubElement5>Milkshakes</SubElement5>
            </Element2>
        </Level1>
    </abc1>
        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>

ZZZ
苹果
橘子
梨
蓝莓
奶昔
XXX
苹果
橘子
猕猴桃
蓝莓
奶昔
那么单元格j的值就是“奶昔”

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
提前感谢任何能提供帮助的人

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
回答这个问题:

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
下面总结Woody所做的工作,以供将来参考:

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

<xsl:template match="/abc1">
           <xsl:variable name="elements" select="//Element1[not(preceding::Element1 = .)]"/>
<table>
<tr> 
    <td width="180" > Row 1</td>
    <td width="540" colspan="4"> Cell_A</td>
</tr>
<tr> 
    <td width="180" >Types</td>
    <td width="180" >Type 1</td>
    <td width="180" >Type 2</td>
    <td width="180" >Type 3</td>
</tr>
<tr> 
    <td width="180" >Row 2</td>
    <td width="180" > <xsl:for-each select="$elements">
            <xsl:if test="position() != 1">,</xsl:if>
            <xsl:choose>
                <xsl:when test=". = 'AAA'">40</xsl:when>
                <xsl:when test=". = 'BBB'">50</xsl:when>
                <xsl:when test=". = 'XXX'">100</xsl:when>
                <xsl:when test=". = 'ZZZ'">10</xsl:when>
            </xsl:choose>
        </xsl:for-each></td>
    <td width="180" ><xsl:for-each select="$elements">
            <xsl:if test="position() != 1">,</xsl:if>
            <xsl:choose>
                <xsl:when test=". = 'AAA'">30</xsl:when>
                <xsl:when test=". = 'BBB'">30</xsl:when>
                <xsl:when test=". = 'XXX'">90</xsl:when>
                <xsl:when test=". = 'ZZZ'">20</xsl:when>
            </xsl:choose>
        </xsl:for-each></td>
    <td width="180" ><xsl:for-each select="$elements">
            <xsl:if test="position() != 1">,</xsl:if>
            <xsl:choose>
                <xsl:when test=". = 'AAA'">30</xsl:when>
                <xsl:when test=". = 'BBB'">20</xsl:when>
                <xsl:when test=". = 'XXX'">80</xsl:when>
                <xsl:when test=". = 'ZZZ'">30</xsl:when>
            </xsl:choose>
        </xsl:for-each></td>
</tr>
<tr> 
    <td width="180" > Row 3</td>
    <td width="180" >Cell_E</td>
    <td width="180" >Cell_F</td>
    <td width="180" >Cell_G</td>
</tr>
<tr> 
    <td width="180" >Row 4</td>
    <td width="180" >Cell_H</td>
    <td width="180" >Cell_I</td>
    <td width="180" ><xsl:for-each select="//SubElement5[not(preceding::SubElement5/text() = text())]">
       <xsl:if test="position() &gt; 1">, </xsl:if>
       <xsl:value-of select="."/>
    </xsl:for-each></td>
</tr>
<tr> 
    <td width="180" > Row 5</td>
    <td width="540" colspan="4"> Cell_K</td>
</tr>
</table>
        </xsl:template>
    </xsl:stylesheet>
        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>

一排
单元A
类型
类型1
类型2
类型3
第2排
,
40
50
100
10
,
30
30
90
20
,
30
20
80
30
第3排
单元E
单元F
细胞
第4排
单元H
第一单元
, 
第5行
单元K

伍迪,再次谢谢你。这太棒了。

你的问题的关键在于你无法通过数据获取你想要的,因为你想要的答案是固定的,即,如果这个,输出那个,如果那个,输出这个。所以你需要一次完成每个部分

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
只有两个级别1吗

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>

第2排
10
20
30
100
90
80
10,100
20,90
30,80
.. 继续的
每节等等。如果您有许多行,并且希望它们以逗号分隔,那么您需要在每个节中进行分隔 或者,如果您必须为每个部分放置一个逗号列表

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
对不起,我看不出你想用cell_j做什么,而且似乎没有其他的规则

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
编辑:但是,如果您有很多项,而不仅仅是2项,并且需要一个逗号分隔的列表,那么可以使用xpath进行编辑,因此:

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
<tr>
  <td>
    <xsl:for-each select="//SubElement5[not(preceding::SubElement5/text() = text())]">
       <xsl:if test="position() &gt; 1">, </xsl:if>
       <xsl:value-of select="."/>
    </xsl:for-each>
  </td>
  .. maybe other rows the same
</tr>

, 
.. 也许其他行也一样
再次编辑:

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
因此,对于您关于cell_j的更新问题,上面给出了正确的值

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
对于第一部分中的更新,如果希望显示所有值,可以对同一主题进行更改(因此,如果您拥有所有4个选项,则有4个值)。不幸的是,由于每个都有固定的值,并且必须逐个执行,因此需要在一个大的部分中执行,因此在循环中:

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
<xsl:for-each select="//Element1[not(preceding::Element1/text() = text())]">

这将使您在每个唯一条目的循环中,然后根据该值是否为XXX、ZZZ等有一个choose元素

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
再次编辑

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>
有几种方法可以完成您想要的第一部分,包括递归函数、外部文档和使用各种不同XSLT实现的节点集函数,但作为一种完全通用的易于查看的方法,这是一个稍微冗长但易于查看的版本(我希望):

        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>

第2排
,
40
50
100
10
,
30
30
90
20
,
30
20
80
30

实际上-我不确定对变量($elements在本例中)的迭代是否是那个标准,它可能是saxon和msxsl的东西,但如果不是,您可以用值(//Element1[not(preference::Element1=))

您忘了指定进入单元格E、F、G的内容,H和I。请编辑问题并提供缺少的信息。感谢您的帮助。为了回答你们的问题,我将在我原来的帖子中添加一些额外的信息。再次感谢你们。你能用一个例子来扩展最后一节吗?我不太清楚你的意思。我的意思是,一旦你确定了你有哪些独特的元素,你就必须把它们放在每个元素中,你必须做3次测试,每个td测试一次,因为没有办法存储值和打印值。因此,即使你做了一个测试,发现ZZZ存在,并且你知道所有tds中的所有3个值,你必须在开始第二个之前完成第一个td。我现在还没有机会把它写下来
        <xsl:template match="/abc1">
            <table>
                <tr> 
                    <td width="180" >Row 2</td>
            <xsl:choose>
                <xsl:when test="not(Level1/Element1='XXX')">
                    <!-- only ZZZ -->
                        <td width="180" >10</td>
                        <td width="180" >20</td>
                        <td width="180" >30</td>
                </xsl:when>
                <xsl:when test="not(Level1/Element1='ZZZ')">
                    <!-- only YYY -->
                        <td width="180" >100</td>
                        <td width="180" >90</td>
                        <td width="180" >80</td>   
                </xsl:when>
                <xsl:otherwise>
                    <!-- some combination -->
                        <td width="180" >10,100</td>
                        <td width="180" >20,90</td>
                        <td width="180" >30,80</td>
                </xsl:otherwise>
                </xsl:choose>
                </tr>
                .. continued
            </table>
        </xsl:template>
    </xsl:stylesheet>