Arrays 类数组索引

Arrays 类数组索引,arrays,xslt,indexing,Arrays,Xslt,Indexing,XML代码: <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <notold> <list>1</list> <list>2</list> </notold> <cd> <title>Empire Burlesque</title> <artist>Bob Dyl

XML代码:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<notold>
    <list>1</list>
    <list>2</list>
</notold>
<cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
</cd>
<cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
</cd>
<cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1985</year>
</cd>
</catalog>

1.
2.
皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
1988
最成功的
多莉·帕顿
美国
RCA
9.90
1985
XSLT代码:

    <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <h2>My CD Collection</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
    <th>Title</th>
    <th>Artist</th>
        </tr>
        <xsl:for-each select="catalog/cd">
        <tr>

        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
        <td><xsl:value-of select="year"/></td>
        <xsl:if test='year=1985'>
          <td><xsl:value-of select="/catalog/notold"></td>
    </xsl:if>
        </xsl>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

我的CD收藏
标题
艺术家
我想给第一个匹配号1和第二个匹配号2。但问题是,每场比赛后,它同时给出1和2。我怎样才能使每次比赛只使用一个号码

谢谢

输出:

<table border="1">
<tbody><tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
<td>1985</td>
<td>
1
2
</td>
</tr>
<tr>
<td>Hide your heart</td>
<td>Bonnie Tyler</td>
<td>1988</td>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
<td>1985</td>
<td>
1
2
</td>
</tr>
</tbody></table>

标题
艺术家
皇帝讽刺剧
鲍勃·迪伦
1985
1.
2.
隐藏你的心
邦尼泰勒
1988
最成功的
多莉·帕顿
1985
1.
2.
编辑:


19389
19390
装载时间
加载时间19389676
中值的
中位数19389868
加载时间193901777
中位数193901508

我想这就是你想要的——假设你想要鲍勃·迪伦拥有第一个
notald/list
(即“1”),邦妮·泰勒没有数字,多莉·帕顿拥有第二个
notald/list

它的工作原理是在匹配同一筛选器的所有cd的列表中查找当前匹配cd的位置,计算匹配列表中的前一个同级
s,然后根据基于1的索引访问相应的
notald/list

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <xsl:for-each select="catalog/cd">
                <tr>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="artist"/></td>
                    <td><xsl:value-of select="year"/></td>
                    <xsl:if test='year=1985'>
                        <td>
                            <xsl:variable name='index' 
                                          select='count(preceding-sibling::cd[year=1985]) + 1' />
                            <xsl:value-of select="/catalog/notold/list[position()=$index]" />
                        </td>
                    </xsl:if>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>

我的CD收藏
标题
艺术家

谢谢,这太棒了!编辑完零件后,您能再次检查上面的代码吗?例如,buildid=19390 value=1777应该显示,但它没有显示。@user1754665-尝试将
更改为
。您能将这两个特定问题概括为一个包含这两种情况的问题吗?这将更有帮助,更容易消化。
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <h2>Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <xsl:for-each select="cdash/builds/build">
                <tr>
                    <td><xsl:value-of select="buildid"/></td>

                <td>
        <xsl:if test='buildid = /cdash/etests/etest/buildid'>
                            <xsl:variable name='index' 
                                          select='count(preceding-sibling::build[buildid = /cdash/etests/etest/buildid]) + 1' />
                            <xsl:value-of select="/cdash/etests/etest/value[position()=$index]" />
        </xsl:if>
                        </td>

                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <xsl:for-each select="catalog/cd">
                <tr>
                    <td><xsl:value-of select="title"/></td>
                    <td><xsl:value-of select="artist"/></td>
                    <td><xsl:value-of select="year"/></td>
                    <xsl:if test='year=1985'>
                        <td>
                            <xsl:variable name='index' 
                                          select='count(preceding-sibling::cd[year=1985]) + 1' />
                            <xsl:value-of select="/catalog/notold/list[position()=$index]" />
                        </td>
                    </xsl:if>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>