我被限制为vanilla XSLT1.0(没有扩展名)和MSXML转换
完全陷入困境。
我有一个XML,我需要从中创建HTML输出。节点需要按version_code排序,然后按despatch_tape_colour排序,然后按地址_line_1分组(更容易看下面的图片看:奶油色标题是组头)
<order>
<order_no>16292</order_no>
<job_no>16292</job_no>
<loads>
<LoadID>10</LoadID>
<load_seq>10</load_seq>
<load_address_1>731 Fraser Street</load_address_1>
<load_haulier>Purolator</load_haulier>
<load_splits>
<load_split_id>10</load_split_id>
<load_split_description>Prince Rupert Northern View</load_split_description>
<version_code>Z1</version_code>
<despatch_tape_colour>FLAT</despatch_tape_colour>
</load_splits>
</loads>
<loads>
<LoadID>11</LoadID>
<load_seq>11</load_seq>
<load_address_1>8506 Main Street</load_address_1>
<load_haulier>Purolator</load_haulier>
<load_splits>
<load_split_id>11</load_split_id>
<load_split_description>*</load_split_description>
<version_code>Z1</version_code>
<despatch_tape_colour>FLAT</despatch_tape_colour>
</load_splits>
</loads>
<loads>
<LoadID>19</LoadID>
<load_seq>19</load_seq>
<load_address_1>130 - 766 Cliveden Place</load_address_1>
<load_haulier>Purolator</load_haulier>
<load_splits>
<load_split_id>19</load_split_id>
<load_split_description>*</load_split_description>
<version_code>Z1</version_code>
<despatch_tape_colour>FLAT</despatch_tape_colour>
</load_splits>
</loads>
<loads>
<LoadID>123</LoadID>
<load_seq>123</load_seq>
<load_address_1>100 Railway Avenue West</load_address_1>
<load_haulier>Purolator</load_haulier>
<load_splits>
<load_split_id>123</load_split_id>
<load_split_description>*</load_split_description>
<version_code>Z2</version_code>
<despatch_tape_colour>FLAT</despatch_tape_colour>
</load_splits>
</loads>
<loads>
<LoadID>124</LoadID>
<load_seq>124</load_seq>
<load_address_1>130 - 766 Cliveden Place</load_address_1>
<load_haulier>Purolator</load_haulier>
<load_splits>
<load_split_id>124</load_split_id>
<load_split_description>*</load_split_description>
<version_code>Z2</version_code>
<despatch_tape_colour>FLAT</despatch_tape_colour>
</load_splits>
</loads>
</order>
在下图中,您可以看到19和124组合在一起,因为它们都具有相同的address_line_1(它要求19按照它的顺序出现)。问题是节点124随后出现,并再次与19组合。我需要做的是忽略已经迭代或包含在前一组中的load_split_ids。
我能想到的另一种方式(可能是:-))解决它是创建和msxml节点集然后迭代它,但我想看看是否有另一种方法< / p>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html"/>
<xsl:variable name="template_version">1.0.0.26</xsl:variable>
<xsl:variable name="template_date">7th August 2016</xsl:variable>
<!-- Based on Shipments v1.0.0.8 -->
<xsl:variable name="currency_symbol"/>
<xsl:key name="unique_load_addresses_version_format" match="/order/loads[starts-with(load_haulier, 'Purolator')]/load_splits" use="concat(../load_address_1,'_',version_code,'_',despatch_tape_colour)"/>
<xsl:include href="Globals_pdf.xsl"/>
<xsl:template match="order">
<html>
<head>
<!-- PrinceXML: Adding UTF-8 stops browser interpreting   as A-circumflex followed by a <space> -->
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/>
<style type="text/css">
body {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:8pt;}
h1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 22pt; font-weight: bold; margin: 0 0 10px 0;}
.outer { width: 100%; }
.tax { width: 100%;}
table {font-family: Verdana, Arial, Helvetica, sans-serif;cellspacing: 0px; cellpadding: 0px; border-width: 0; border-collapse: collapse; border-spacing: 0px; width: 100%; }
td {vertical-align: top; font-family: Verdana, Arial, Helvetica, sans-serif; padding: 5px 1px 5px 1px; font-size: 8pt; border-width: 1pt; border-style: solid; border-color: <xsl:value-of select="$color2"/>; }
th {text-align: left; vertical-align: bottom; background-color: LightSteelBlue; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: normal; padding: 5px 1px 5px 1px; border-width: 1pt; border-style: solid; border-color: <xsl:value-of select="$color2"/>; border-collapse: collapse; border-spacing: 0px; color: black;}
.bold { font-weight: bold; }
.grey {background-color: #dddddd; }
.proforma { color: black; }
.heading { vertical-align: bottom; text-align: center;}
.bottom_center { vertical-align: bottom; text-align: center; }
.top_center { vertical-align: top; text-align: center; }
.top_left { vertical-align: top; text-align: left; }
.middle_left { vertical-align: middle; text-align: left; }
.middle_center { vertical-align: middle; text-align: center; }
.top_right { vertical-align: top; text-align: right; }
.bottom_left { vertical-align: bottom; text-align: left; }
.bottom_right { vertical-align: bottom; text-align: right; }
.left_indent {padding-left: 70px;}
.top_indent {padding-top: 35px;}
.label {font-weight: bold; width: 15%; padding-top: 2px; padding-bottom: 2px; padding-right: 5px; text-align: right; width: 30%; font-size: 12pt;}
.contents {padding-left: 5mm; width: 30%; padding-top: 2px; padding-bottom: 2px; width: 70%; font-size: 12pt;}
hr {border: none; background-color: black; height: 0.5pt;}
.first_row { border-top: 2pt solid red; }
.red {color: #aa0000; }
</style>
</head>
<body>
<table class="loads" style="">
<tr>
<th>S/P/I</th>
<th>Zone</th>
<th>Format</th>
<th>Address</th>
<th>Carrier</th>
</tr>
<xsl:for-each select="/order/loads[starts-with(load_haulier, 'Purolator')]/load_splits[generate-id() = generate-id(key('unique_load_addresses_version_format', concat(../load_address_1,'_',version_code,'_',despatch_tape_colour))[1])]">
<xsl:sort select="concat(version_code,'_',despatch_tape_colour)" data-type="text" />
<xsl:variable name="curr_address" select="../load_address_1"/>
<tr>
<td style="background-color: #fdf5e6; color: blue; border-top: 2px solid grey">Load/LoadSplitID: <xsl:value-of select="../LoadID"/>/<xsl:value-of select="load_split_id"/></td>
<td style="background-color: #fdf5e6; color: blue; border-top: 2px solid grey"><xsl:value-of select="version_code"/></td>
<td style="background-color: #fdf5e6; color: blue; border-top: 2px solid grey"><xsl:value-of select="despatch_tape_colour"/></td>
<td style="background-color: #fdf5e6; color: blue; border-top: 2px solid grey"><xsl:value-of select="../load_address_1"/></td>
<td style="background-color: #fdf5e6; color: blue; border-top: 2px solid grey"></td>
</tr>
<xsl:for-each select="/order/loads[starts-with(load_haulier, 'Purolator') and load_address_1 = $curr_address]/load_splits">
<xsl:sort select="concat(version_code,'_',despatch_tape_colour)" data-type="text" order="ascending" />
<xsl:variable name="part_ref" select="load_despatch_code"/>
<xsl:variable name="line_type">
<xsl:choose>
<xsl:when test="position() = 1">S</xsl:when>
<xsl:otherwise>P</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr>
<td>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="position()=1">color: red; border-top: 2px solid black</xsl:when>
<xsl:when test="position()=last()">color: black;</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="load_split_id"/>
</td>
<td>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="position()=1">color: red; border-top: 2px solid black</xsl:when>
<xsl:when test="position()=last()">color: black;</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="version_code"/>
</td>
<td>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="position()=1">color: red; border-top: 2px solid black</xsl:when>
<xsl:when test="position()=last()">color: black;</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="despatch_tape_colour"/>
</td>
<td>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="position()=1">color: red; border-top: 2px solid black</xsl:when>
<xsl:when test="position()=last()">color: black;</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="../load_address_1"/>
</td>
<td>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="position()=1">color: red; border-top: 2px solid black</xsl:when>
<xsl:when test="position()=last()">color: black;</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="../load_haulier"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
任何XSL向导都有任何建议吗?
TIA
标记