Xml 在xslt中使用xsl:when

Xml 在xslt中使用xsl:when,xml,xslt-1.0,Xml,Xslt 1.0,在我的XSLT中,我输出的客户的SIM卡涉及国家代码49、区号31和号码124567。在When中,我将输出与这些号码相关的、以特定颜色确认identity=0的任何客户 我需要另一个when,它可以输出具有多张不同颜色SIM卡的客户,这些SIM卡的号码包括国家代码49、区号31、号码124567。拥有多张SIM卡的客户在SIM/SIM节点内多次重复customerID。我不知道如何输出具有多张不同颜色SIM卡的客户。我想我需要两个whens XML代码: <database>

在我的XSLT中,我输出的客户的SIM卡涉及国家代码49、区号31和号码124567。在
When
中,我将输出与这些号码相关的、以特定颜色确认identity=0的任何客户

我需要另一个
when
,它可以输出具有多张不同颜色SIM卡的客户,这些SIM卡的号码包括国家代码49、区号31、号码124567。拥有多张SIM卡的客户在SIM/SIM节点内多次重复customerID。我不知道如何输出具有多张不同颜色SIM卡的客户。我想我需要两个
when
s

XML代码:

<database>
  <customers>
    <customer>
      <customerID>1</customerID>
      <surname>Aardvark</surname>
      <firstname>John</firstname>
      <streetAddress>101 High Street</streetAddress>
      <townName>Dorptown</townName>
      <countyName>Wicklow</countyName>
      <contractOrPrepaid>contract</contractOrPrepaid>
      <confirmedIdentity>1</confirmedIdentity>
    </customer>
    <customer>
      <customerID>2</customerID>
      <surname>Brown</surname>
      <firstname>James</firstname>
      <streetAddress>102 High Street</streetAddress>
      <townName>Dorptown</townName>
      <countyName>Wicklow</countyName>
      <contractOrPrepaid>prepaid</contractOrPrepaid>
      <confirmedIdentity>0</confirmedIdentity>
    </customer>
    <customer>
      <customerID>3</customerID>
      <surname>Brown</surname>
      <firstname>Jack</firstname>
      <streetAddress>103 Main Street</streetAddress>
      <townName>Dorpville</townName>
      <countyName>Cork</countyName>
      <contractOrPrepaid>prepaid</contractOrPrepaid>
      <confirmedIdentity>1</confirmedIdentity>
    </customer>
    <customer>
      <customerID>4</customerID>
      <surname>Carroll</surname>
      <firstname>Jack</firstname>
      <streetAddress>103 Main Street</streetAddress>
      <townName>Dorpton</townName>
      <countyName>Kilkenny</countyName>
      <contractOrPrepaid>prepaid</contractOrPrepaid>
      <confirmedIdentity>0</confirmedIdentity>
    </customer>
    <customer>
      <customerID>5</customerID>
      <surname>Brown</surname>
      <firstname>Peter</firstname>
      <streetAddress>103 Main Street</streetAddress>
      <townName>Dorpborough</townName>
      <countyName>Kilkenny</countyName>
      <contractOrPrepaid>contract</contractOrPrepaid>
      <confirmedIdentity>1</confirmedIdentity>
    </customer>
    <customer>
      <customerID>6</customerID>
      <surname>Brown</surname>
      <firstname>Xavier</firstname>
      <streetAddress>103 Main Street</streetAddress>
      <townName>Dorpley</townName>
      <countyName>Kilkenny</countyName>
      <contractOrPrepaid>contract</contractOrPrepaid>
      <confirmedIdentity>1</confirmedIdentity>
    </customer>
    <customer>
      <customerID>7</customerID>
      <surname>Brown</surname>
      <firstname>Xavier</firstname>
      <streetAddress>103 Main Street</streetAddress>
      <townName>Dorpton Bridge</townName>
      <countyName>Wexford</countyName>
      <contractOrPrepaid>prepaid</contractOrPrepaid>
      <confirmedIdentity>0</confirmedIdentity>
    </customer>
    <customer>
      <customerID>8</customerID>
      <surname>Brown</surname>
      <firstname>Xavier</firstname>
      <streetAddress>103 High Street</streetAddress>
      <townName>New Dorpley</townName>
      <countyName>Carlow</countyName>
      <contractOrPrepaid>prepaid</contractOrPrepaid>
      <confirmedIdentity>0</confirmedIdentity>
    </customer>
  </customers>
  <sims>
    <sim>
      <simID>1</simID>
      <areaCode>081</areaCode>
      <number>1234567</number>
      <customerID>1</customerID>
      <yearPurchased>1995</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>2</simID>
      <areaCode>081</areaCode>
      <number>1234568</number>
      <customerID>2</customerID>
      <yearPurchased>1995</yearPurchased>
      <monthPurchased>11</monthPurchased>
      <dayPurchsed>11</dayPurchsed>
    </sim>
    <sim>
      <simID>3</simID>
      <areaCode>081</areaCode>
      <number>1234569</number>
      <customerID>3</customerID>
      <yearPurchased>1996</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>4</simID>
      <areaCode>081</areaCode>
      <number>1234570</number>
      <customerID>4</customerID>
      <yearPurchased>1997</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>5</simID>
      <areaCode>081</areaCode>
      <number>1234571</number>
      <customerID>5</customerID>
      <yearPurchased>1998</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>6</simID>
      <areaCode>081</areaCode>
      <number>1234572</number>
      <customerID>6</customerID>
      <yearPurchased>1999</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>7</simID>
      <areaCode>081</areaCode>
      <number>1234573</number>
      <customerID>7</customerID>
      <yearPurchased>2000</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>8</simID>
      <areaCode>081</areaCode>
      <number>1234574</number>
      <customerID>8</customerID>
      <yearPurchased>2001</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>9</simID>
      <areaCode>081</areaCode>
      <number>1234575</number>
      <customerID>1</customerID>
      <yearPurchased>2001</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>10</simID>
      <areaCode>081</areaCode>
      <number>1234576</number>
      <customerID>2</customerID>
      <yearPurchased>2002</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>11</simID>
      <areaCode>081</areaCode>
      <number>1234577</number>
      <customerID>3</customerID>
      <yearPurchased>2003</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>12</simID>
      <areaCode>081</areaCode>
      <number>1234578</number>
      <customerID>4</customerID>
      <yearPurchased>2004</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>13</simID>
      <areaCode>081</areaCode>
      <number>1234579</number>
      <customerID>4</customerID>
      <yearPurchased>2005</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>14</simID>
      <areaCode>081</areaCode>
      <number>1234580</number>
      <customerID>5</customerID>
      <yearPurchased>2006</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>15</simID>
      <areaCode>081</areaCode>
      <number>1234581</number>
      <customerID>5</customerID>
      <yearPurchased>2007</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
    <sim>
      <simID>16</simID>
      <areaCode>081</areaCode>
      <number>1234582</number>
      <customerID>5</customerID>
      <yearPurchased>2008</yearPurchased>
      <monthPurchased>10</monthPurchased>
      <dayPurchsed>12</dayPurchsed>
    </sim>
  </sims>
  <calls>
    <call>
      <callID>12345678901234567890</callID>
      <simID>1</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>12</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567891</callID>
      <simID>2</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>13</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567892</callID>
      <simID>3</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>14</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567893</callID>
      <simID>4</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>15</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567894</callID>
      <simID>5</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>16</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567895</callID>
      <simID>6</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>17</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567896</callID>
      <simID>7</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>18</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567897</callID>
      <simID>8</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>19</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567898</callID>
      <simID>9</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>20</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567899</callID>
      <simID>10</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>44</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>123</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>21</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567900</callID>
      <simID>11</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>353</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>021</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>22</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567901</callID>
      <simID>12</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>353</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>056</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>7654321</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>23</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567902</callID>
      <simID>2</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>49</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>31</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>124567</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>24</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567903</callID>
      <simID>14</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>49</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>31</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>124567</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>25</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567904</callID>
      <simID>6</simID>
      <madeOrReceived>made</madeOrReceived>
      <countryCodeOfOtherParty>49</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>31</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>124567</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>26</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
    <call>
      <callID>12345678901234567905</callID>
      <simID>7</simID>
      <madeOrReceived>received</madeOrReceived>
      <countryCodeOfOtherParty>49</countryCodeOfOtherParty>
      <areaCodeOfOtherParty>31</areaCodeOfOtherParty>
      <numberCodeOfOtherParty>124567</numberCodeOfOtherParty>
      <year>2009</year>
      <month>10</month>
      <day>27</day>
      <hour>12</hour>
      <minute>12</minute>
      <second>5</second>
    </call>
  </calls>
</database>

1.
土豚
约翰
高街101号
多普敦
威克洛
合同
1.
2.
棕色的
詹姆斯
高街102号
多普敦
威克洛
预付款的
0
3.
棕色的
杰克
大街103号
多尔维尔
软木
预付款的
1.
4.
卡罗尔
杰克
大街103号
多普顿
基尔肯尼
预付款的
0
5.
棕色的
彼得
大街103号
多普布罗
基尔肯尼
合同
1.
6.
棕色的
泽维尔
大街103号
多普利
基尔肯尼
合同
1.
7.
棕色的
泽维尔
大街103号
多普顿桥
韦克斯福德
预付款的
0
8.
棕色的
泽维尔
高街103号
新多普利
卡洛
预付款的
0
1.
081
1234567
1.
1995
10
12
2.
081
1234568
2.
1995
11
11
3.
081
1234569
3.
1996
10
12
4.
081
1234570
4.
1997
10
12
5.
081
1234571
5.
1998
10
12
6.
081
1234572
6.
1999
10
12
7.
081
1234573
7.
2000
10
12
8.
081
1234574
8.
2001
10
12
9
081
1234575
1.
2001
10
12
10
081
1234576
2.
2002
10
12
11
081
1234577
3.
2003
10
12
12
081
1234578
4.
2004
10
12
13
081
1234579
4.
2005
10
12
14
081
1234580
5.
2006
10
12
15
081
1234581
5.
2007
10
12
16
081
1234582
5.
2008
10
12
12345678901234567890
1.
收到
44
123
7654321
2009
10
12
12
12
5.
12345678901234567891
2.
…制造的
44
123
7654321
2009
10
13
12
12
5.
12345678901234567892
3.
…制造的
44
123
7654321
2009
10
14
12
12
5.
12345678901234567893
4.
收到
44
123
7654321
2009
10
15
12
12
5.
12345678901234567894
5.
收到
44
123
7654321
2009
10
16
12
12
5.
12345678901234567895
6.
收到
44
123
7654321
2009
10
17
12
12
5.
12345678901234567896
7.
…制造的
44
123
7654321
2009
10
18
12
12
5.
12345678901234567897
8.
…制造的
44
123
7654321
2009
10
19
12
12
5.
12345678901234567898
9
…制造的
44
123
7654321
2009
10
20
12
12
5.
12345678901234567899
10
…制造的
44
123
7654321
2009
10
21
12
12
5.
12345678901234567900
11
收到
353
021
7654321
2009
10
22
12
12
5.
12345678901234567901
12
…制造的
353
056
7654321
2009
10
23
12
12
5.
12345678901234567902
2.
收到
49
31
124567
2009
10
24
12
12
5.
12345678901234567903
14
收到
49
31
124567
2009
10
25
12
12
5.
12345678901234567904
6.
…制造的
49
31
124567
2009
10
26
12
12
5.
12345678901234567905
7.
收到
49
31
124567
2009
10
27
12
12
5.
XSLT代码:

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

  <xsl:key name="customerid" match="database/sims/sim" use="customerID" />

  <xsl:template match="/">
    <html>
      <head>
        <title>Customers</title>
      </head>
      <body>
        <table rules="all">
          <caption>Customers</caption>
          <thead>
            <tr>
              <th>Firstname</th>
              <th>Surname</th>
            </tr>
          </thead>

          <xsl:for-each select="database/calls/call">

            <xsl:if test="countryCodeOfOtherParty  = '49' and areaCodeOfOtherParty ='31' and numberCodeOfOtherParty ='124567'">

              <xsl:variable name="callsimID" select="./simID"/>

              <xsl:for-each select= "/database/sims/sim[simID = $callsimID]">

                <xsl:variable name="simCustomerID" select="./customerID"/>

                <xsl:for-each select= "/database/customers/customer[customerID = $simCustomerID]">

                  <tr>
                    <xsl:choose>
                      <xsl:when test="confirmedIdentity=0">
                        <td bgcolor="#FFA500">
                          <xsl:value-of select="firstname"/>
                        </td>
                        <td bgcolor="#FFA500">
                          <xsl:value-of select="surname"/>
                        </td>
                      </xsl:when>

                    </xsl:choose>
                  </tr>

                </xsl:for-each>

              </xsl:for-each>
            </xsl:if>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

客户
客户
名字
姓
以下是您如何
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:key name="simsById" match="sim" use="simID" />
  <xsl:key name="customersById" match="customer" use="customerID" />
  <xsl:key name="simsByCustomerId" match="database/sims/sim" 
           use="customerID" />

  <xsl:template match="/">
    <html>
      <head>
        <title>Customers</title>
        <style>
          tr.unconfirmed td { background-color: #FFA500; }
          tr.multisim    td { background-color: Green; }
        </style>
      </head>
      <body>
        <table rules="all">
          <caption>Customers</caption>
          <thead>
            <tr>
              <th>Firstname</th>
              <th>Surname</th>
            </tr>
          </thead>

          <xsl:apply-templates
              select="database/calls/call[countryCodeOfOtherParty  = '49' and
                                          areaCodeOfOtherParty ='31' and 
                                          numberCodeOfOtherParty ='124567']" />
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="call">
     <xsl:apply-templates select="key('customersById', 
                                      key('simsById', simID)/customerID)" />
  </xsl:template>

  <xsl:template match="customer">
    <tr>
      <xsl:attribute name="class">
        <xsl:apply-templates select="." mode="determineClass" />
      </xsl:attribute>
      <td>
        <xsl:value-of select="firstname"/>
      </td>
      <td>
        <xsl:value-of select="surname"/>
      </td>
    </tr>
  </xsl:template>

  <!-- Below is the part that determines a row's class -->

  <!-- Catch-all for customers with no special formatting -->
  <xsl:template match="customer" mode="determineClass" />

  <xsl:template match="customer[confirmedIdentity = 0]" mode="determineClass">
    <xsl:text>unconfirmed</xsl:text>
  </xsl:template>

  <xsl:template match="customer[key('simsByCustomerId', customerID)[2]]"
                mode="determineClass">
    <xsl:text>multisim</xsl:text>
  </xsl:template>

</xsl:stylesheet>
<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Customers</title>
    <style>
          tr.unconfirmed td { background-color: #FFA500; }
          tr.multisim    td { background-color: Green; }
        </style>
  </head>
  <body>
    <table rules="all">
      <caption>Customers</caption>
      <thead>
        <tr>
          <th>Firstname</th>
          <th>Surname</th>
        </tr>
      </thead>
      <tr class="multisim">
        <td>James</td>
        <td>Brown</td>
      </tr>
      <tr class="multisim">
        <td>Peter</td>
        <td>Brown</td>
      </tr>
      <tr class="">
        <td>Xavier</td>
        <td>Brown</td>
      </tr>
      <tr class="unconfirmed">
        <td>Xavier</td>
        <td>Brown</td>
      </tr>
    </table>
  </body>
</html>