我是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>
答案 0 :(得分:0)
看看这对你有意义:
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>