将当前组逻辑的 XSL 2.0 计数转换为 XSL 1.0 逻辑

Convert XSL 2.0 count by current-group logic into XSL 1.0 logic

我是 XSL 的新手,正在尝试根据数据子串的分组来总结一些 XML 数据。

我一直在尝试着手研究 Muenchian 分组和计数,但一直未能成功。我查看了 XSL 2.0 格式并使用以下代码在 5 分钟内解决了我的问题。

我的问题是我需要它在 XSL 1.0 中工作。

有人可以帮我把这个逻辑转换成 XSL 1.0 格式吗?

这是有效的 XSL 2.0 代码

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
    <html>
        <head>
            <meta charset="utf-8"/>
            <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0"/>
        </head>
        <body>
            <p>
                <table align="center">
                    <thead>
                        <tr>
                            <th>Bay</th>
                            <th>Units</th>
                            <th>20'</th>
                            <th>40'</th>
                            <th>45'</th>
                            <th>Breakbulk</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each-group select="StowplanTransactions/Group2"
                            group-by="substring(LocationIdentification/@LocationID, 1, 3)">
                            <xsl:sort select="LocationIdentification/@LocationID"/>
                            <tr>
                                <td>
                                    <xsl:value-of select="current-grouping-key()"/>
                                </td>
                                <td>
                                    <xsl:value-of select="count(current-group())"/>
                                </td>
                                <td>
                                    <xsl:value-of
                                        select="count(current-group()/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '2']/@EquipmentSizeTypeIdentification)"
                                    />
                                </td>
                                <td>
                                    <xsl:value-of
                                        select="count(current-group()/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '4']/@EquipmentSizeTypeIdentification)"
                                    />
                                </td>
                                <td>
                                    <xsl:value-of
                                        select="count(current-group()/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '9' or substring(@EquipmentSizeTypeIdentification, 1, 1) = 'L']/@EquipmentSizeTypeIdentification)"
                                    />
                                </td>
                                <td>
                                    <xsl:value-of
                                        select="count(current-group()/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '']/@EquipmentSizeTypeIdentification)"
                                    />
                                </td>
                            </tr>
                        </xsl:for-each-group>
                    </tbody>
                </table>
            </p>
        </body>
    </html>
</xsl:template>

这是我当前的 XLS 1.0 代码。分组工作正常,组中的成员数也在工作,但我需要计算属性在组中具有特定值的位置。目前最后4个计数字段都显示为0。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:key name="StowageCellBay" match="//StowplanTransactions/Group2/LocationIdentification"
    use="substring(@LocationID, 1, 3)"/>
<xsl:template match="/">
    <html>
        <head>
            <meta charset="utf-8"/>
            <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0"/>
        </head>
        <body>
            <p>
                <table align="center" border="1">
                    <thead>
                        <tr>
                            <th>Bay</th>
                            <th>Units</th>
                            <th>20'</th>
                            <th>40'</th>
                            <th>45'</th>
                            <th>Breakbulk</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="StowplanTransactions/Group2">
                            <xsl:sort select="LocationIdentification/@LocationID"/>
                            <xsl:for-each
                                select="
                                    LocationIdentification[generate-id() =
                                    generate-id(key('StowageCellBay', substring(@LocationID, 1, 3))[1])]">
                                <tr>
                                    <td>
                                        <xsl:value-of select="substring(@LocationID, 1, 3)"/>
                                    </td>
                                    <td>
                                        <xsl:value-of
                                            select="count(key('StowageCellBay', substring(@LocationID, 1, 3)))"
                                        />
                                    </td>
                                    <td>
                                        <xsl:value-of
                                            select="count(Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '2']/@EquipmentSizeTypeIdentification)"
                                        />
                                    </td>
                                    <td>
                                        <xsl:value-of
                                            select="count(Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '4']/@EquipmentSizeTypeIdentification)"
                                        />
                                    </td>
                                    <td>
                                        <xsl:value-of
                                            select="count(Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = 'L' or substring(@EquipmentSizeTypeIdentification, 1, 1) = '9']/@EquipmentSizeTypeIdentification)"
                                        />
                                    </td>
                                    <td>
                                        <xsl:value-of
                                            select="count(Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '']/@EquipmentSizeTypeIdentification)"
                                        />
                                    </td>
                                </tr>
                            </xsl:for-each>
                        </xsl:for-each>
                    </tbody>
                </table>
            </p>
        </body>
    </html>
</xsl:template>

这里是 XML 来源的例子

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StowplanTransactions>
<Group2>
    <LocationIdentification LocationID="0610390" />
    <Group3>
        <EquipmentDetails  EquipmentIdentificationNumber="11111111111"
            EquipmentSizeTypeIdentification="22G1"/>
    </Group3>
</Group2>
<Group2>
    <LocationIdentification LocationID="0340612" />
    <Group3>
        <EquipmentDetails EquipmentIdentificationNumber="22222222222"
            EquipmentSizeTypeIdentification="42G1" />
    </Group3>
</Group2>
<Group2>
    <LocationIdentification LocationID="0650004"/>
    <Group3>
        <EquipmentDetails EquipmentIdentificationNumber="33333333333"
            EquipmentSizeTypeIdentification="" />
    </Group3>
</Group2>
<Group2>
    <LocationIdentification LocationID="0650306"/>
    <Group3>
        <EquipmentDetails EquipmentIdentificationNumber="44444444444"
            EquipmentSizeTypeIdentification="22G1" />
    </Group3>
</Group2>
<Group2>
    <LocationIdentification LocationID="0730220"/>
    <Group3>
        <EquipmentDetails EquipmentIdentificationNumber="55555555555"
            EquipmentSizeTypeIdentification="L591"/>
    </Group3>
</Group2>

看看这对你是否有意义:

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:template match="/StowplanTransactions">
    <table align="center" border="1">
        <thead>
            <tr>
                <th>Bay</th>
                <th>Units</th>
                <th>20'</th>
                <th>40'</th>
                <th>45'</th>
                <th>Breakbulk</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:value-of select="count($curr-group/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '2']/@EquipmentSizeTypeIdentification)"/>
                    </td>
                    <td>
                        <xsl:value-of select="count($curr-group/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '4']/@EquipmentSizeTypeIdentification)"/>
                    </td>
                    <td>
                        <xsl:value-of select="count($curr-group/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '9' or substring(@EquipmentSizeTypeIdentification, 1, 1) = 'L']/@EquipmentSizeTypeIdentification)"/>
                    </td>
                    <td>
                        <xsl:value-of select="count($curr-group/Group3/EquipmentDetails[substring(@EquipmentSizeTypeIdentification, 1, 1) = '']/@EquipmentSizeTypeIdentification)"/>
                    </td>
                </tr>
            </xsl:for-each>
        </tbody>
    </table>
</xsl:template>

</xsl:stylesheet>