-1
這是我的XML:檢查是否至少有一個元素是不同
<SECTION_CONTENT_LIST_ITEM> <------- First Group
<NTC_LIGHTLISTPRODUCT>
<IMMUTABLE_ID>5585</IMMUTABLE_ID>
<INTERNATIONAL_LIGHT_NUMBER>E1283</INTERNATIONAL_LIGHT_NUMBER>
<VICINITY>LA SPEZIA</VICINITY>
<LIGHT_INFORMATION_LIST>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>G</LIGHT_COLOUR> <-- LIGHT_COLOUR G
<LIGHT_HEIGHT>8</LIGHT_HEIGHT>
<LIGHT_RANGE>3</LIGHT_RANGE> <-- LIGHT_RANGE 3
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>R</LIGHT_COLOUR> <-- LIGHT_COLOUR R
<LIGHT_HEIGHT>6</LIGHT_HEIGHT>
<LIGHT_RANGE>3</LIGHT_RANGE> <-- LIGHT_RANGE 3
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
</LIGHT_INFORMATION_LIST>
</NTC_LIGHTLISTPRODUCT>
</SECTION_CONTENT_LIST_ITEM>
<SECTION_CONTENT_LIST_ITEM> <--- Second Group
<NTC_LIGHTLISTPRODUCT>
<IMMUTABLE_ID>5586</IMMUTABLE_ID>
<INTERNATIONAL_LIGHT_NUMBER>E1324</INTERNATIONAL_LIGHT_NUMBER>
<VICINITY>LERICI</VICINITY>
<LIGHT_INFORMATION_LIST>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>G</LIGHT_COLOUR> <-- LIGHT_COLOUR G
<LIGHT_HEIGHT>7</LIGHT_HEIGHT>
<LIGHT_RANGE>3</LIGHT_RANGE> <-- LIGHT_RANGE 3
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>G</LIGHT_COLOUR> <-- LIGHT_COLOUR G
<LIGHT_HEIGHT>6</LIGHT_HEIGHT>
<LIGHT_RANGE>3</LIGHT_RANGE> <-- LIGHT_RANGE 3
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
</LIGHT_INFORMATION_LIST>
</NTC_LIGHTLISTPRODUCT>
</SECTION_CONTENT_LIST_ITEM>
<SECTION_CONTENT_LIST_ITEM> <--- Third Group
<NTC_LIGHTLISTPRODUCT>
<IMMUTABLE_ID>5574</IMMUTABLE_ID>
<INTERNATIONAL_LIGHT_NUMBER>E1328.5</INTERNATIONAL_LIGHT_NUMBER>
<VICINITY>MARINA DI CARRARA</VICINITY>
<LIGHT_INFORMATION_LIST>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>W-G</LIGHT_COLOUR> <-- Contains'-', go to the next
<LIGHT_SIGNAL_GROUP>()</LIGHT_SIGNAL_GROUP>
<LIGHT_HEIGHT>32</LIGHT_HEIGHT>
<LIGHT_RANGE>12</LIGHT_RANGE>
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>R</LIGHT_COLOUR> <-- LIGHT_COLOUR R
<LIGHT_HEIGHT>32</LIGHT_HEIGHT>
<LIGHT_RANGE>10</LIGHT_RANGE> <-- LIGHT_RANGE 10
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>G</LIGHT_COLOUR> <-- LIGHT_COLOUR G
<LIGHT_HEIGHT>32</LIGHT_HEIGHT>
<LIGHT_RANGE>10</LIGHT_RANGE> <-- LIGHT_RANGE 10
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
<LIGHT_INFORMATION>
<LIGHT_COLOUR>W</LIGHT_COLOUR> <-- LIGHT_COLOUR W
<LIGHT_HEIGHT>32</LIGHT_HEIGHT>
<LIGHT_RANGE>12</LIGHT_RANGE> <-- LIGHT_RANGE 12
<LIGHT_STATUS>Priv</LIGHT_STATUS>
</LIGHT_INFORMATION>
</LIGHT_INFORMATION_LIST>
</NTC_LIGHTLISTPRODUCT>
</SECTION_CONTENT_LIST_ITEM>
這是我的XSLT:
<td style="text-align:center; width:0.99cm; color:red; padding-left:3; padding-right:3" valign="top">
<xsl:for-each select="LIGHT_INFORMATION_LIST/LIGHT_INFORMATION/LIGHT_RANGE[not(contains(preceding-sibling::LIGHT_COLOUR, '-'))]">
<!-- Prendo le lettere dei colori in LIGHT_COLOUR-->
<xsl:variable name="LCorrente" select="preceding-sibling::LIGHT_COLOUR"/>
<xsl:variable name="LPrecedente" select="preceding::LIGHT_RANGE[1][not(contains(preceding-sibling::LIGHT_COLOUR, '-'))][preceding::IMMUTABLE_ID = $EF]/preceding-sibling::LIGHT_COLOUR"/>
<!-- Prendo i numeri di portata in LIGHT_RANGE-->
<xsl:variable name="NCorrente" select="number(.)"/>
<xsl:variable name="NPrecedente" select="number(preceding::LIGHT_RANGE[1][not(contains(preceding-sibling::LIGHT_COLOUR, '-'))][preceding::IMMUTABLE_ID=$EF])"/>
<xsl:if test="not($LPrecedente) or $LPrecedente != $LCorrente" >
<xsl:value-of select="$LCorrente"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$NCorrente"/>
<br/>
</xsl:if>
</xsl:for-each>
</td>
這是輸出:
做出修正是以下內容:
予解釋:
在第一種情況:
LIGHT_RANGE所有元素等於3(或其它數目)在這種情況下不輸出I將「3」重要LIGHT_COLOUR;
在第二種情況下:
LIGHT_COLOUR和LIGHT_RANGE是相同的,寫'3';
在第三種情況下:
如果Light_COLOUR包含' - '則轉到下一個。如果至少一個LIGHT_RANGE不同的是還必須採取各的特點,並獲得輸出,R 10 - 克10和W 12
大家展示一下我們是不是[Muenchian分組的(HTTP:// WWW .jenitennison.com/XSLT /分組/ muenchian.html)。 – 2014-10-29 14:47:02
謝謝邁克爾,不是一個Muenchian分組。 – 2014-12-09 16:26:45