XSLT排序还是分组依据?
我有以下xml文件:XSLT排序还是分组依据?,xslt,Xslt,我有以下xml文件: <DATABLOCK> <LINE> <DATA>010000</DATA> <DATA>User1@MSAD</DATA> <DATA>User2@MSAD</DATA> <DEBIT></DEBIT> <CREDIT>-0</CREDIT>
<DATABLOCK>
<LINE>
<DATA>010000</DATA>
<DATA>User1@MSAD</DATA>
<DATA>User2@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>-0</CREDIT>
</LINE>
<LINE>
<DATA></DATA>
<DATA>User1@MSAD</DATA>
<DATA>User2@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>-0</CREDIT>
</LINE>
<LINE>
<DATA>010002</DATA>
<DATA>User3@MSAD</DATA>
<DATA>User2@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>0</CREDIT>
</LINE>
<LINE>
<DATA></DATA>
<DATA>User3@MSAD</DATA>
<DATA>User2@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>-0</CREDIT>
</LINE>
<LINE>
<DATA></DATA>
<DATA>User3@MSAD</DATA>
<DATA>User2@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>0</CREDIT>
</LINE>
<LINE>
<DATA>010003</DATA>
<DATA>User4@MSAD</DATA>
<DATA>User5@MSAD</DATA>
<DEBIT></DEBIT>
<CREDIT>640,650</CREDIT>
</LINE>
<LINE>
<DATA></DATA>
<DATA>User4@MSAD</DATA>
<DATA>User5@MSAD</DATA>
<DEBIT>567,103</DEBIT>
<CREDIT></CREDIT>
</LINE>
<LINE>
<DATA></DATA>
<DATA>User4@MSAD</DATA>
<DATA>User5@MSAD</DATA>
<DEBIT>73,547</DEBIT>
<CREDIT></CREDIT>
</LINE>
</DATABLOCK>
我对XSLT完全不熟悉,在网上找到一些似乎适用的东西,但不完全理解语法以及如何为我的场景修改语法。只需将for each条件更改为
<xsl:for-each select="DATABLOCK/LINE[not(DATA[1]/text()='')]">
这将限制for each仅处理第一个数据元素中具有非空文本节点的行。如果这些行已经分组和排序,则看起来您可以只渲染具有第一个
数据
元素值的行,而跳过其余行:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="DATABLOCK">
<html>
<body>
<h1>Posted Journals:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Journal</th>
<th>Approved By</th>
<th>Posted By</th>
</tr>
<xsl:apply-templates />
</table>
</body>
</html>
</xsl:template>
<!--Do not render LINEs that do not have a value for the first DATA element-->
<xsl:template match="LINE[not(normalize-space(DATA[1]))]"/>
<!--Each LINE element will be renderd as a Row-->
<xsl:template match="LINE">
<tr><xsl:apply-templates select="DATA"/></tr>
</xsl:template>
<!--Each DATA element will be a column -->
<xsl:template match="DATA">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
已过账日记账:
杂志
批准人
邮寄人
+1个写得很好的问题
<xsl:for-each select="DATABLOCK/LINE[not(DATA[1]/text()='')]">
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="DATABLOCK">
<html>
<body>
<h1>Posted Journals:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Journal</th>
<th>Approved By</th>
<th>Posted By</th>
</tr>
<xsl:apply-templates />
</table>
</body>
</html>
</xsl:template>
<!--Do not render LINEs that do not have a value for the first DATA element-->
<xsl:template match="LINE[not(normalize-space(DATA[1]))]"/>
<!--Each LINE element will be renderd as a Row-->
<xsl:template match="LINE">
<tr><xsl:apply-templates select="DATA"/></tr>
</xsl:template>
<!--Each DATA element will be a column -->
<xsl:template match="DATA">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>