在我的XSLT中,我输出的SIM卡涉及国家代码49,区号31和号码124567的客户。在When
我输出任何已确认身份= 0的客户,其颜色为参与了这些数字。
我还需要另一个when
输出拥有多张不同颜色SIM卡的客户,这些客户还需要输入国家代码49,区号31,电话号码124567.拥有多张SIM卡的客户在SIM / SIM节点内重复使用customerID多次。我不确定如何使用不同颜色的多个SIM卡输出客户。我想我需要两个when
。
XML CODE:
<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>
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>
答案 0 :(得分:1)
以下是如何使这个XSLT更加整洁并完成您所描述的内容:
<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>