gpt4 book ai didi

xml - 仅为 XSL 1.0 中的特定条件列出组内属性的唯一值

转载 作者:数据小太阳 更新时间:2023-10-29 02:40:02 26 4
gpt4 key购买 nike

当另一个属性具有特定值时,我需要列出组中属性的唯一值。在 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>

我需要弄清楚的是如何在 LocationQualifier='12' 的 LocationIdentification1 中列出 LocationID 的唯一值

期望的输出

<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>

关于xml - 仅为 XSL 1.0 中的特定条件列出组内属性的唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com