3
當另一個屬性具有特定值時,需要列出組中屬性的唯一值。在XSL 1.0中進行這項工作非常難以理解。僅在XSL 1.0中列出組中屬性的唯一值。
感謝另一篇文章,我現在已經定義了分組,以便在屬性匹配特定條件時執行計數。然而,我很難僅列出一個特定屬性的唯一值,其中另一個屬性等於特定值,但僅限於當前組的成員內。
與往常一樣,這將對示例源數據和代碼更有意義。
下面是示例XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Group1>
<Group2>
<LocationIdentification LocationID="0610390" />
<LocationIdentification1 LocationQualifier="12" LocationID="USLGB"/>
</Group2>
<Group2>
<LocationIdentification LocationID="0610612" />
<LocationIdentification1 LocationQualifier="12" LocationID="USLAX"/>
</Group2>
<Group2>
<LocationIdentification LocationID="0650004"/>
<LocationIdentification1 LocationQualifier="12" LocationID="USLGB"/>
</Group2>
<Group2>
<LocationIdentification LocationID="0650306"/>
<LocationIdentification1 LocationQualifier="6" LocationID="USLAX"/>
</Group2>
<Group2>
<LocationIdentification LocationID="0650220"/>
<LocationIdentification1 LocationQualifier="12" LocationID="USLGB"/>
</Group2>
</Group1>
我有XSL集合以創建基於從LocationIdentification節點屬性LocationID的前3個字符組。
XSL 1.0
<xsl:stylesheet version="1.0"
<xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:key name="grp" match="Group2" use="substring(LocationIdentification/@LocationID, 1, 3)"/>
<xsl:template match="/Group1">
<table align="center" border="1">
<thead>
<tr>
<th>Bay</th>
<th>Units</th>
<th>Locations</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="Group2[generate-id()=generate-id(key('grp', substring(LocationIdentification/@LocationID, 1, 3))[1])]">
<xsl:sort select="LocationIdentification/@LocationID"/>
<xsl:variable name="curr-key" select="substring(LocationIdentification/@LocationID, 1, 3)" />
<xsl:variable name="curr-group" select="key('grp', $curr-key)" />
<tr>
<td>
<xsl:value-of select="$curr-key"/>
</td>
<td>
<xsl:value-of select="count($curr-group)"/>
</td>
<td>
<!-- NEW CODE NEEDS TO GO HERE -->
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
我需要弄清楚,是如何內LocationIdentification1其中LocationQualifier = '12'
所需的輸出
<table align="center" border="1">
<thead>
<tr>
<th>Bay</th>
<th>Count</th>
<th>Location(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>061</td>
<td>2</td>
<td>USLGB USLAX</td>
</tr>
<tr>
<td>065</td>
<td>3</td>
<td>USLGB</td>
</tr>
</table>
列出LocationID的獨特價值
請注意,Bay 65的計數爲3,但只有2 o f成員具有12的LocationQualifier,並且它們都具有相同的LocationID值,因此輸出結果應該只列出USLGB的位置。
感謝邁克爾 – MarkT