仅为 XSL 1.0 中的特定条件列出组内属性的唯一值
List unique values of an attribute within a group only for specific criteria in XSL 1.0
当另一个属性具有特定值时,我需要列出组中一个属性的唯一值。在 XSL 1.0 中实现这项工作非常难以理解。
感谢另一个 post,我现在定义了分组,允许我在属性匹配特定条件时执行计数。但是,我无法列出一个特定属性的唯一值,其中另一个属性等于特定值,但仅限于当前组的成员。
一如既往,这对于示例源数据和代码来说更有意义。
这是示例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 中列出 LocationID 的唯一值,其中 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>
请注意,Bay 65 的计数为 3,但只有 2 个成员的 LocationQualifier 为 12,并且它们都具有相同的 LocationID 值,因此输出应仅列出 Location(s) 的 USLGB。
您需要进行另一轮 Muenchian 分组:
XSLT 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:key name="loc12" match="LocationIdentification1[@LocationQualifier='12']" use="concat(substring(../LocationIdentification/@LocationID, 1, 3), '|', @LocationID)"/>
<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>
<xsl:for-each select="$curr-group/LocationIdentification1[@LocationQualifier='12'][generate-id()=generate-id(key('loc12', concat($curr-key, '|', @LocationID))[1])]">
<xsl:value-of select="@LocationID"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
当另一个属性具有特定值时,我需要列出组中一个属性的唯一值。在 XSL 1.0 中实现这项工作非常难以理解。
感谢另一个 post,我现在定义了分组,允许我在属性匹配特定条件时执行计数。但是,我无法列出一个特定属性的唯一值,其中另一个属性等于特定值,但仅限于当前组的成员。
一如既往,这对于示例源数据和代码来说更有意义。
这是示例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 中列出 LocationID 的唯一值,其中 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>
请注意,Bay 65 的计数为 3,但只有 2 个成员的 LocationQualifier 为 12,并且它们都具有相同的 LocationID 值,因此输出应仅列出 Location(s) 的 USLGB。
您需要进行另一轮 Muenchian 分组:
XSLT 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:key name="loc12" match="LocationIdentification1[@LocationQualifier='12']" use="concat(substring(../LocationIdentification/@LocationID, 1, 3), '|', @LocationID)"/>
<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>
<xsl:for-each select="$curr-group/LocationIdentification1[@LocationQualifier='12'][generate-id()=generate-id(key('loc12', concat($curr-key, '|', @LocationID))[1])]">
<xsl:value-of select="@LocationID"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>