我的XSL输出卡住了HTML。 我创建了一个页面,显示按关系编号排序的文档信息,在发送给客户之前需要经过Manager批准,显示文档类型(以及我在此问题中删除的许多其他信息)。
目前我在浏览器中获得了一个输出
Relation number Document sort
2222222 Jaarbrief
2222222 Brief
99999999 Jaarbrief-addendum
99999999 Jaarbrief
99999999 Brief
我想要的是输出
Relation number Document sort
22222222 Jaarbrief
Brief
22224325 Jaarbrief-addendum
Jaarbrief
Brief
33333333 Jaarbrief
Brief
我正在尝试使用XSL for-each-groups,但我无法以正确的方式完成它。
XSL代码:
<?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"
encoding="UTF-8"
indent="yes" />
<xsl:template match="files">
<xsl:variable name = "count" select ="@count" />
<xsl:variable name = "AUsr" select ="@user" />
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="static/css/main.css" rel="stylesheet" type="text/css"></link>
<link href="static/css/gotham.css" rel="stylesheet" type="text/css"></link>
<link href="static/css/sub-style.css" rel="stylesheet" type="text/css" media="screen"></link>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="static/css/default.js">xslthelper</script>
<script src="static/js/cookie.js"></script>
<script src="static/js/ui.js"></script>
<!--[if lt IE 9]>
<script src="static/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="body-content">
<div class="wrap">
<br/>
<form method="POST" id="myform" name="myform" action="PostProlo" enctype="multipart/form-data">
<div class="module">
<table width="100%" id="match_tbl" name="match_tbl">
<tr valign="top" align="center">
<th width="16px"></th>
<th width="80px" >Relatie nummer</th>
<th width="70px" >Document<BR/>soort</th>
</tr>
<xsl:for-each select="folder/file[Pages[1]/Page[1]/Dummy='FACTUUR']">
<xsl:sort select="Pages[1]/Page[1]/Relatienummer" data-type="text" />
<xsl:sort select="Pages[1]/Page[1]/Type" data-type="text" order="descending"/>
<!-- Sortering volgorde : html table view -->
<!-- All data fields to variables, also the not used fields for easy re-use : html table view -->
<xsl:variable name = "file" select ="filename" />
<xsl:variable name = "path" select ="path" />
<xsl:variable name = "Count" select ="@Count" />
<xsl:variable name = "fileShort" select ="substring($file,1,string-length($file)-4)" />
<xsl:variable name = "fileShow" select ="substring($file,1,string-length($file)-20)" />
<xsl:variable name = "Formsoort" select ="Pages[1]/Page[1]/Duplex" />
<xsl:variable name = "Typedoc" select ="Pages[1]/Page[1]/Type" />
<xsl:variable name = "Relatienummer" select ="Pages[1]/Page[1]/Relatienummer" />
<xsl:variable name = "Type" select ="Pages[1]/Page[1]/Type" />
<xsl:variable name = "Datum" select ="Pages[1]/Page[1]/Datum" />
<xsl:variable name = "Tijd" select ="Pages[1]/Page[1]/Time" />
<xsl:variable name = "OrderNo" select ="string(format-number(position(), '00000'))" />
<!-- html table definition starts here, with above variables used if neccesary -->
<tr valign="top" align="left">
<td>
<input id="Mname{$OrderNo}" name="Mname{$OrderNo}" type="hidden" value="{$fileShort}" />
<input id="Mpath{$OrderNo}" name="Mpath{$OrderNo}" type="hidden" value="{$path}" />
<input id="Type{$OrderNo}" name="Type{$OrderNo}" type="hidden" value="{$Type}" />
<input id="Relatienummer{$OrderNo}" name="Relatienummer{$OrderNo}" type="hidden" value="{$Relatienummer}" />
<input class="ng_checkbox2 refreshbox" type="checkbox" id="MID{$OrderNo}" name="MPDF{$OrderNo}" />
</td>
<td align="center"><xsl:value-of select="$Relatienummer" />
</td>
<td align="center"><xsl:value-of select="$Type" />
</td>
</tr>
</xsl:for-each>
</table>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
使用的XML
<?xml version="1.0" encoding="UTF-8"?>
<files user="ADMIN" D_Printer="">
<folder>
<file Count="1">
<Pages Count="1">
<Page>
<Dummy>FACTUUR</Dummy>
<Datum>28-10-2015</Datum>
<Tijd>10:52</Tijd>
<Type>Brief</Type>
<Gebruiker>USERX</Gebruiker>
<Relatienummer>2222222</Relatienummer>
</Page>
</Pages>
<filename>99999999_Brief_00ZSY1Y4UEZWX81 - Copy.xml</filename>
<path>C:\Connect\WF\Wachtrij\PPWORKDIR\UserQueues\ADMIN\</path>
<time>2016/01/18 12:07:18</time>
<size>891</size>
</file>
<file Count="1">
<Pages Count="1">
<Page>
<Dummy>FACTUUR</Dummy>
<Datum>28-10-2015</Datum>
<Tijd>10:52</Tijd>
<Type>Brief</Type>
<Gebruiker>USERX</Gebruiker>
<Relatienummer>99999999</Relatienummer>
</Page>
</Pages>
<filename>99999999_Brief_00ZSY1Y4UEZWX81.xml</filename>
<path>C:\Connect\WF\Wachtrij\PPWORKDIR\UserQueues\ADMIN\</path>
<time>2016/01/18 12:06:10</time>
<size>892</size>
</file>
<file Count="1">
<Pages Count="1">
<Page>
<Dummy>FACTUUR</Dummy>
<Datum>28-10-2015</Datum>
<Tijd>10:52</Tijd>
<Type>Jaarbrief</Type>
<Gebruiker>USERX</Gebruiker>
<Relatienummer>2222222</Relatienummer>
</Page>
</Pages>
<filename>99999999_Brief_00ZSY1YU093NZF2 - Copy - Copy.xml</filename>
<path>C:\Connect\WF\Wachtrij\PPWORKDIR\UserQueues\ADMIN\</path>
<time>2016/01/18 12:07:34</time>
<size>899</size>
</file>
<file Count="1">
<Pages Count="1">
<Page>
<Dummy>FACTUUR</Dummy>
<Datum>28-10-2015</Datum>
<Tijd>10:52</Tijd>
<Type>Jaarbrief</Type>
<Gebruiker>USERX</Gebruiker>
<Relatienummer>99999999</Relatienummer>
</Page>
</Pages>
<filename>99999999_Brief_00ZSY1YU093NZF2 - Copy.xml</filename>
<path>C:\Connect\WF\Wachtrij\PPWORKDIR\UserQueues\ADMIN\</path>
<time>2016/01/18 12:06:46</time>
<size>900</size>
</file>
<file Count="1">
<Pages Count="1">
<Page>
<Dummy>FACTUUR</Dummy>
<Datum>28-10-2015</Datum>
<Tijd>10:52</Tijd>
<Type>Jaarbrief-addendum</Type>
<Gebruiker>USERX</Gebruiker>
<Relatienummer>99999999</Relatienummer>
</Page>
</Pages>
<filename>99999999_Brief_00ZSY1YU093NZF2.xml</filename>
<path>C:\Connect\WF\Wachtrij\PPWORKDIR\UserQueues\ADMIN\</path>
<time>2015/12/03 16:40:46</time>
<size>909</size>
</file>
<file>
<filename>dummy.xml</filename>
<path>C:\UserQueues\ADMIN\</path>
<time>2016/01/18 12:14:32</time>
<size>445</size>
</file>
</folder>
</files>
我希望你能帮助我,如果我错过任何所需的信息,请告诉我。 非常感谢提前
答案 0 :(得分:0)
看起来您要按照第一页中指定的file
对Relatienummer
元素进行分组,因此xsl:for-each-group
看起来像这样
然后,您需要迭代当前组中的元素,以便输出行
<xsl:for-each select="current-group()">
然后你可以检查它是否是组中的第一行来决定是否输出数字
<xsl:if test="position() = 1">
<xsl:value-of select="current-grouping-key()" />
</xsl:if>
尝试使用此简化的XSLT作为起点
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:template match="files">
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<th>Relation number</th>
<th>Document sort</th>
</tr>
<xsl:for-each-group select="folder/file" group-by="Pages/Page[1]/Relatienummer">
<xsl:for-each select="current-group()">
<tr>
<td>
<xsl:if test="position() = 1">
<xsl:value-of select="current-grouping-key()" />
</xsl:if>
</td>
<td><xsl:value-of select="Pages/Page[1]/Type" /></td>
</tr>
</xsl:for-each>
</xsl:for-each-group>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>