我正在尝试按日期和时间对此 xml 进行排序
<?xml version="1.0" encoding="utf-8"?>
<FormComments>
<Comments EventName="Position Clearance">
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:47 PM]]>
</DateTime>
<Body>
<![CDATA[Clearance is obtained]]>
</Body>
<Action>
<![CDATA[Clearance Obtained]]>
</Action>
</Comment>
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:50 PM]]>
</DateTime>
<Body>
<![CDATA[Clearance already obtained]]>
</Body>
<Action>
<![CDATA[Clearance Obtained]]>
</Action>
</Comment>
</Comments>
<Comments EventName="Comp Advisor">
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:48 PM]]>
</DateTime>
<Body>
<![CDATA[This form needs modifications!!]]>
</Body>
<Action>
<![CDATA[Modifications Needed]]>
</Action>
</Comment>
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:51 PM]]>
</DateTime>
<Body>
<![CDATA[Still not up to par!]]>
</Body>
<Action>
<![CDATA[Deny]]>
</Action>
</Comment>
</Comments>
<Comments EventName="Modify">
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:49 PM]]>
</DateTime>
<Body>
<![CDATA[Done fixing the form]]>
</Body>
<Action>
<![CDATA[Changes Made Resubmit]]>
</Action>
</Comment>
</Comments>
<Comments EventName="How to Proceed">
<Comment>
<IsWindowsUser>
<![CDATA[True]]>
</IsWindowsUser>
<UserName>
<![CDATA[DOMAIN\userId]]>
</UserName>
<DisplayName>
<![CDATA[DOMAIN\userId]]>
</DisplayName>
<DateTime>
<![CDATA[12/21/2012 2:52 PM]]>
</DateTime>
<Body>
<![CDATA[Forget it!!!]]>
</Body>
<Action>
<![CDATA[Stop]]>
</Action>
</Comment>
</Comments>
</FormComments>
我想出了这个
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<STYLE TYPE="text/css">
TD{
font-family: Arial; font-size: 9pt;
background color:"#939495";
}
TD.Center{
text-align:"center";
}
TH{
background color:"#B31B34";
}
caption{
font-size:20pt;
}
</STYLE>
<hr />
<table cellpadding='8' border='1'>
<caption>Workflow Information </caption>
<th>Event</th>
<th>Approver</th>
<th>Action</th>
<th>Comment</th>
<th>Time</th>
<xsl:for-each select="FormComments/Comments">
<!-- Sort by year -->
<xsl:sort select="substring-before(substring-after(substring-after(Comment/DateTime,'/'),'/'),' ')"/>
<!-- Sort by Month -->
<xsl:sort select="substring(normalize-space(Comment/DateTime),1,2)"/>
<!-- Sort by AM / PM -->
<xsl:sort select="substring-after(substring-after(normalize-space(Comment/DateTime), ' '),' ')"/>
<!-- Sort by hour -->
<xsl:sort select="substring-before(substring-after(substring-after(Comment/DateTime,' '),' '),':')"/>
<!-- Sort by minute -->
<xsl:sort select="substring-before(substring-after(normalize-space(Comment/DateTime), ':'),' ')"/>
<xsl:variable name="eventName">
<xsl:value-of select="@EventName" />
</xsl:variable>
<xsl:for-each select="Comment">
<xsl:variable name="User">
<xsl:value-of select="UserName" />
</xsl:variable>
<tr>
<td>
<xsl:copy-of select="$eventName" />
</td>
<td>
<xsl:copy-of select="substring-after($User,'\')" />
</td>
<td class="Center">
<xsl:value-of select="Action"/>
</td>
<td>
<xsl:value-of select="Body"/>
</td>
<td>
<xsl:value-of select="DateTime"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
问题是它只在评论节点内排序,而不是在所有评论节点中排序。
我无法发布图片,因为我刚刚注册了这个网站......输出看起来像
Workflow Information
Event Approver Action Comment Time
Position Clearance tf114096 Clearance Obtained Clearance is obtained 12/21/2012 2:47 PM
Position Clearance rbg14096 Clearance Obtained Clearance already obtained 12/21/2012 2:50 PM
Comp Advisor thy14096 Modifications Needed This form needs modifications!! 12/21/2012 2:48 PM
Comp Advisor trw14096 Deny Still not up to par! 12/21/2012 2:51 PM
Modify we214096 Changes Made Resubmit Done fixing the form 12/21/2012 2:49 PM
How to Proceed cf414096 Stop Forget it!!! 12/21/2012 2:52 PM
请注意,发生两次的事件在该事件中排序,但不是针对所有其他事件。鉴于这种 XML 结构,有没有办法对此进行排序?
我一直在使用这个在线工具来测试我的 XSLT http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
预期结果应如下所示
Workflow Information
Event Approver Action Comment Time
Position Clearance tf114096 Clearance Obtained Clearance is obtained 12/21/2012 2:47 PM
Comp Advisor thy14096 Modifications Needed This form needs modifications!! 12/21/2012 2:48 PM
Modify we214096 Changes Made Resubmit Done fixing the form 12/21/2012 2:49 PM
Position Clearance rbg14096 Clearance Obtained Clearance already obtained 12/21/2012 2:50 PM
Comp Advisor trw14096 Deny Still not up to par! 12/21/2012 2:51 PM
How to Proceed cf414096 Stop Forget it!!! 12/21/2012 2:52 PM
结果完全排序..