没有重复的排序表

时间:2021-05-21 10:40:33

标签: xml xslt

早上好,

我有一个具有以下结构的 XML 文件:

<Reports>
    <UUTs>
        <Results>
        <SerialNumberToSearch></SerialNumberToSearch>
            <Result ID="0">
                <SerialNumber>1234</SerialNumber>
                <Status>Fail</Status>
                <Date>2021-03-05T08:15:21</Date>
            </Result>
            <Result ID="1">
                <SerialNumber>1234</SerialNumber>
                <Status>Fail</Status>
                <Date>2021-03-05T08:23:23</Date>
            </Result>
            <Result ID="2">
                <SerialNumber>1234</SerialNumber>
                <Status>Fail</Status>
                <Date>2021-03-05T08:16:23</Date>
            </Result>
            <Result ID="3">
                <SerialNumber>6556175708</SerialNumber>
                <Status>Pass</Status>
                <Date>2021-03-05T09:15:21</Date>
            </Result>
            <Result ID="4">
                <SerialNumber>1234</SerialNumber>
                <Status>Pass</Status>
                <Date>2021-03-05T08:17:21</Date>
            </Result>
            <Result ID="5">
                <SerialNumber>11908817202</SerialNumber>
                <Status>Pass</Status>
                <Date>2021-03-05T07:11:21</Date>
            </Result>
            <Result ID="6">
                <SerialNumber>2406339084</SerialNumber>
                <Status>Pass</Status>
                <Date>2021-03-05T08:15:21</Date>
            </Result>
        </Results>
    </UUTs>
</Reports>

我想将此 XML 转换为按日期排序且没有 SerialNumber 重复项的表。这就是我到目前为止所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>


<xsl:strip-space elements="*"/>
<xsl:template match="UUTs/Results">
    <fo:block >
        <fo:table table-layout="fixed" width="100%"> 
            <fo:table-header>
                <fo:table-row keep-with-next="always" background-color="#EAEAEA">
                    <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                        <fo:block font-weight="bold" font-family="sans-serif">Serial Number</fo:block>
                    </fo:table-cell>
                    <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                        <fo:block font-weight="bold" font-family="sans-serif">Test Result</fo:block>
                    </fo:table-cell>
                    <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                        <fo:block font-weight="bold" font-family="sans-serif">Date</fo:block>
                    </fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                        <fo:block font-weight="bold" font-family="sans-serif">Time</fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </fo:table-header>
            
            <fo:table-body>
            <xsl:for-each select="Result">
                <xsl:sort select="./Date" order="descending"/>

                    <fo:table-row>
                        
                        <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                            <fo:block><xsl:value-of select="./SerialNumber"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                            <fo:block><xsl:value-of select="./Status"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                            <fo:block><xsl:value-of select="substring(./Date,0,11)"/></fo:block>
                        </fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="myBorder" padding-left="3mm">
                            <fo:block><xsl:value-of select="substring(./Date,12,8)"/></fo:block>
                        </fo:table-cell>
                        
                        
                    </fo:table-row>
                </xsl:for-each>
            </fo:table-body>    
        </fo:table>
    </fo:block>
</xsl:template>


</xsl:stylesheet>

这是我要查找的表中的输出:

<头>
序列号 测试结果 日期 时间
6556175708 通过 2021-03-05 09:15:21
1234 失败 2021-03-05 08:23:23
11908817202 通过 2021-03-05 07:11:21
2406339084 通过 2021-03-05 07:11:21

我现在需要以某种方式删除 SerialNumber 重复项,但我不知道该怎么做。我尝试了不同的解决方案,但由于我缺乏知识而失败了。

0 个答案:

没有答案
相关问题