我将以下XML作为示例,并希望得到此结果:
20.06.2016
08:30-09:00 TEST_PHX_88
09:30-10:00 TEST_PHX_99
21.06.2016
10:30-11:30 TEST_PHX_66
23.06.2018
09:30-10:00 TEST_PHX_77
09:30-10:30 TEST_PHX_55
因此,列表应按天分组,并按日期内的时间排序
有人可以提供XSL 1.0示例来执行此操作吗?
很多Thx! 劳伦
<XML_DATA>
<GROUPID>1</GROUPID>
<SRO_IF_POLYTERMINE_PRO_PATIENT>
<XRO_PATNAME>TEST_PHX_99</XRO_PATNAME>
<TRMBEGIN_Q>20.06.2018 09:30:00</TRMBEGIN_Q>
<TRMENDE_Q>20.06.2018 10:00:00</TRMENDE_Q>
</SRO_IF_POLYTERMINE_PRO_PATIENT>
<SRO_IF_POLYTERMINE_PRO_PATIENT>
<XRO_PATNAME>TEST_PHX_88</XRO_PATNAME>
<TRMBEGIN_Q>20.06.2018 08:30:00</TRMBEGIN_Q>
<TRMENDE_Q>20.06.2018 09:00:00</TRMENDE_Q>
</SRO_IF_POLYTERMINE_PRO_PATIENT>
<SRO_IF_POLYTERMINE_PRO_PATIENT>
<XRO_PATNAME>TEST_PHX_77</XRO_PATNAME>
<TRMBEGIN_Q>23.06.2018 09:30:00</TRMBEGIN_Q>
<TRMENDE_Q>23.06.2018 10:00:00</TRMENDE_Q>
</SRO_IF_POLYTERMINE_PRO_PATIENT>
<SRO_IF_POLYTERMINE_PRO_PATIENT>
<XRO_PATNAME>TEST_PHX_66</XRO_PATNAME>
<TRMBEGIN_Q>21.06.2018 10:30:00</TRMBEGIN_Q>
<TRMENDE_Q>21.06.2018 11:30:00</TRMENDE_Q>
</SRO_IF_POLYTERMINE_PRO_PATIENT>
<SRO_IF_POLYTERMINE_PRO_PATIENT>
<XRO_PATNAME>TEST_PHX_55</XRO_PATNAME>
<TRMBEGIN_Q>23.06.2018 09:30:00</TRMBEGIN_Q>
<TRMENDE_Q>23.06.2018 10:30:00</TRMENDE_Q>
</SRO_IF_POLYTERMINE_PRO_PATIENT>
</XML_DATA>
答案 0 :(得分:1)
由于您使用的是XSLT 1.0,因此必须使用名为Muenchian Grouping的技术。
对于此要求,将定义一个复合键,其中包含元素date
和<TRMBEGIN_Q>
字符串的<TRMENDE_Q>
部分。
<xsl:key name="keyDate" match="SRO_IF_POLYTERMINE_PRO_PATIENT" use="concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10))" />
接下来,为分组元素运行for-each
循环,在此分组中,元素在复合键上排序,以便21.06.2018
出现在23.06.2018
之前。
<xsl:for-each select="SRO_IF_POLYTERMINE_PRO_PATIENT[generate-id() = generate-id(key('keyDate',concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))[1])]">
<xsl:sort select="substring(key('keyDate', concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))/TRMBEGIN_Q, 1, 10)" />
....
</xsl:for-each>
最后一步是在key
内循环,以提取组内元素的各个值。在此循环中,已应用time
部分的排序。
<xsl:for-each select="key('keyDate', concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))">
<xsl:sort select="substring(TRMBEGIN_Q, 12, 5)" />
....
</xsl:for-each>
以下是完整的XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:strip-space elements="*" />
<xsl:key name="keyDate" match="SRO_IF_POLYTERMINE_PRO_PATIENT" use="concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10))" />
<xsl:template match="XML_DATA">
<table border="0" cellspacing="0" cellpadding="5">
<xsl:for-each select="SRO_IF_POLYTERMINE_PRO_PATIENT[generate-id() = generate-id(key('keyDate',concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))[1])]">
<xsl:sort select="substring(key('keyDate', concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))/TRMBEGIN_Q, 1, 10)" />
<tr>
<td colspan="2">
<b><xsl:value-of select="substring(key('keyDate', concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))/TRMBEGIN_Q, 1, 10)" /></b>
</td>
</tr>
<xsl:for-each select="key('keyDate', concat(substring(TRMBEGIN_Q, 1, 10), '|', substring(TRMENDE_Q, 1, 10)))">
<xsl:sort select="substring(TRMBEGIN_Q, 12, 5)" />
<tr>
<td><xsl:value-of select="concat(substring(TRMBEGIN_Q, 12, 5), ' - ', substring(TRMENDE_Q, 12, 5))" /></td>
<td><xsl:value-of select="XRO_PATNAME" /></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
这将生成一个HTML表格,如下所示。