仅针对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中列出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>

请注意,托架65的计数为3,但是只有2个成员的LocationQualifier为12,并且它们的LocationID值都相同,因此输出应仅列出USLGB作为位置。

michael.hor257k

您需要进行另一轮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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SQL仅针对第1个TRUE条件返回

来自分类Dev

仅针对特定条件的日期

来自分类Dev

.htaccess重写带有问号“?”的URL 仅针对1个特定的URL

来自分类Dev

负载均衡器仅针对特定URL重定向到服务器1

来自分类Dev

仅针对特定<div>的BlockUI

来自分类Dev

在列中仅列出唯一值

来自分类Dev

xlst查询的分组仅针对每个select值显示1个标头,而不显示多个标头

来自分类Dev

仅针对特定网站的热链接预防

来自分类Dev

仅针对特定操作忽略ValidateAntiForgeryToken

来自分类Dev

Dotnetnuke仅针对特定模块注入脚本

来自分类Dev

仅针对特定网站的热链接预防

来自分类Dev

仅针对特定网址的出站链接跟踪

来自分类Dev

针对仅包含一对的模式匹配

来自分类Dev

仅获取 1 列上每个唯一值的最新值

来自分类Dev

pandas df:仅针对B列中唯一的行更改A列中的值

来自分类Dev

查找重复的行,但仅针对唯一列

来自分类Dev

如何使Django模型字段唯一但仅针对单个用户?

来自分类Dev

仅针对特定函数/变量禁用“未使用的属性”警告?

来自分类Dev

针对仅使用一次的值优化变量的使用

来自分类Dev

针对仅使用一次的值优化变量的使用

来自分类Dev

仅针对Bootbox中的特定模态更改模态宽度

来自分类Dev

仅针对Angular中的特定组件调用后端

来自分类Dev

在VIM中仅针对特定文件类型运行设置

来自分类Dev

如何仅针对 TabLayout 中的特定片段停止活动的旋转?

来自分类Dev

仅针对特定元素替换列表中的符号

来自分类Dev

在1列中列出唯一值,并在另一列中串联相应的值

来自分类Dev

SQL仅列出唯一/不同的值

来自分类Dev

SQL仅列出唯一/不同的值

来自分类Dev

仅 1 列的 SQL 条件

Related 相关文章

热门标签

归档