【发布时间】:2015-06-17 21:05:30
【问题描述】:
我是 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>
【问题讨论】:
-
请发布您输入的示例,以便我们可以使用。
-
用正在使用的 XML 示例更新了问题