我有一个以下形式的 xml
<operation>
<update>
<wogroup>id1</wogroup>
<woid>SL0001</woid>
<status>NEW</status>
</update>
<update>
<wogroup>id1</wogroup>
<woid>SL0001</woid>
<status>OPEN</status>
</update>
<update>
<wogroup>id1</wogroup>
<woid>SL0001</woid>
<status>CLOSED</status>
</update>
<update>
<wogroup>id1</wogroup>
<woid>SL0002</woid>
<status>NEW</status>
</update>
<update>
<wogroup>id2</wogroup>
<woid>SL00011</woid>
<status>OVERRIDE</status>
</update>
<update>
<wogroup>id2</wogroup>
<woid>SL00011</woid>
<status>CLOSED</status>
</update>
<update>
<wogroup>id2</wogroup>
<woid>SL00021</woid>
<status>NEW</status>
</update>
</operation>
我对xml的外观没有发言权,但我需要在html中制作报告。我想看到像这样的html
Group : id1
WO : SL001
NEW
OPEN
CLOSED
WO : SL002
NEW
Group : id2
WO : SL0011
OVERRIDE
CLOSED
WO : SL0021
NEW
我成功地在 wogroup 或 wooid 上进行分组,但不是以嵌套的方式......有人建议吗?
我不知道
这是否是最好的方法,但它会根据需要对元素进行分组:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" />
<xsl:key name="updates-by-wogroup" match="/operation/update" use="wogroup" />
<xsl:key name="updates-by-wogroup-and-woid" match="/operation/update" use="concat(wogroup,woid)" />
<xsl:template match="/">
<xsl:for-each select="operation/update[not(wogroup = preceding-sibling::update/wogroup)]">
Group: <xsl:value-of select="wogroup" />
<xsl:for-each select="key('updates-by-wogroup',current()/wogroup)[not(woid = preceding-sibling::update/woid)]">
WO: <xsl:value-of select="woid" />
<xsl:for-each select="key('updates-by-wogroup-and-woid',concat(current()/wogroup,current()/woid))">
<xsl:text>
<xsl:value-of select="status" /></xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如果您成功地按 wogroup 或 woid 分组,您将理解代码,无论如何,如果需要,请提出任何问题。