0

i asked this before but i will try to explain my problem more detailed. Im gettin a XML (the acutal one is a lot bigger as my example here) out of a system where users can book rooms. these rooms are used to communicate from one city to another city. so if one person wants to book he must book at least 2 rooms. i created a table so other user can see who booked which room on what date/time.

table (cant upload images here yet) as u can see the table is not very clear. it has a lot of same values what is not needed. so what i want is i just one date and time and one name for each booking in one . but rooms has to at least 2 in the same for a better view. in my xslt u can also see tried to get a group of nodes in the test

can u help please?

<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href= 'testxsl.xsl'?>
<Objects>
    <Object>
        <Property Name="Datum">01.08.2013</Property>
        <Property Name="Von">04:00:00</Property>
        <Property Name="Bis">06:00:00</Property>
        <Property Name="Raum">Cologne</Property>
        <Property Name="Gebucht_Von">ExamplePerson 1</Property>
    </Object>
    <Object>
        <Property Name="Datum">01.08.2013</Property>
        <Property Name="Von">04:00:00</Property>
        <Property Name="Bis">06:00:00</Property>
        <Property Name="Raum">Munich</Property>
        <Property Name="Gebucht_Von">ExamplePerson 1</Property>
    </Object>
    <Object>
        <Property Name="Datum">01.08.2013</Property>
        <Property Name="Von">08:00:00</Property>
        <Property Name="Bis">12:00:00</Property>
        <Property Name="Raum">Beijing </Property>
        <Property Name="Gebucht_Von">ExpamplePerson 2 </Property>
    </Object>
    <Object>
        <Property Name="Datum">01.08.2013</Property>
        <Property Name="Von">08:00:00</Property>
        <Property Name="Bis">12:00:00</Property>
        <Property Name="Raum">Munich </Property>
        <Property Name="Gebucht_Von">ExpamplePerson 2 </Property>
    </Object>
    <Object>
        <Property Name="Datum">01.08.2013</Property>
        <Property Name="Von">08:30:00</Property>
        <Property Name="Bis">11:00:00</Property>
        <Property Name="Raum">Bombay </Property>
        <Property Name="Gebucht_Von">ExpamplePerson 2 </Property>
    </Object>
</Objects>

XSLT Stylesheet

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"   encoding="iso-8859-1" indent="yes"/>
    <xsl:template match="/">
        <TABLE border="6pt" align="center" >
            <colgroup>
                <col width="150"/>
                <col width="100" />
                <col width="100" />
                <col width="200"/>
                <col width="500"/>
            </colgroup>
            <TR STYLE="font-size:16pt; background-color:#E4FEFF; color:051956; font-family:Times New      Roman',Times,serif"> <!-- Eine Zeile der Tabelle wird geöffnet -->
                <span />
                <TD>
                    <u>
                        <i>Daten</i>
                    </u>
                </TD>
                <TD>
                    <u>
                        <i>From</i>
                    </u>
                </TD>
                <TD>
                    <u>
                        <i>To</i>
                    </u>
                </TD>
                <TD>
                    <u>
                        <i>Room</i>
                    </u>
                </TD>
                <TD>
                    <u>
                        <i>Bookey by</i>
                    </u>
                </TD>
                <TD>
                    <u>
                        <i>test</i>
                    </u>
                </TD>
            </TR>
            <xsl:apply-templates/>
        </TABLE>
    </xsl:template>

    <xsl:template match="Objects">
        <xsl:for-each select="Object">
            <TR STYLE="font-size:13pt;  background-color:#E4FEFF;color:051956; font-family:ARIAL">
                <TD>
                    <xsl:value-of select="Property[1]/text()"/>
                    <TD>
                        <xsl:value-of select="Property[2]/text()"/>
                    </TD>
                    <TD>
                        <xsl:value-of select="Property[3]/text()"/>
                    </TD>
                    <TD>
                        <xsl:value-of select="Property[4]/text()"/>
                    </TD>
                    <TD>
                        <xsl:value-of select="Property[5]/text()"/>
                        <TD>
                            <xsl:value-of select= "current()/Property[(current()/Property[1]= following:: */Property[1])and
                                (current()/Property[2]= following::  */Property[2])and
                                (current()/Property[3]= following:: */Property[3])and
                                (current()/Property[4]!= following::*/Property[4])and
                            (current()/Property[5]= following:: */Property[5])]"/>
                        </TD>
                    </TR>
                </xsl:for-each>
            </xsl:template>
        </xsl:stylesheet>

this is what i want to output

<TABLE border="6pt" align="center">
<colgroup>
    <col width="150">
    <col width="100">
    <col width="100">
    <col width="200">
    <col width="500">
</colgroup>
<TR STYLE="font-size:16pt; background-color:#E4FEFF; color:051956; font-family:Times New Roman',Times,serif"><span></span><TD><u><i>Date</i></u></TD>
    <TD><u><i>From</i></u></TD>
    <TD><u><i>To</i></u></TD>
    <TD><u><i>Room</i></u></TD>
    <TD><u><i>Booked by</i></u></TD>
</TR>
<TR STYLE="font-size:13pt;  background-color:#E4FEFF;color:051956; font-family:ARIAL">
    <TD>01.08.2013</TD>
    <TD>04:00:00</TD>
    <TD>06:00:00</TD>
    <TD>Cologne, Munich</TD>
    <TD>ExamplePerson 1</TD>
</TR>
<TR STYLE="font-size:13pt;  background-color:#E4FEFF;color:051956; font-family:ARIAL">
    <TD>01.08.2013</TD>
    <TD>08:00:00</TD>
    <TD>12:00:00</TD>
    <TD>Beijing, Munich, Bombay </TD>
    <TD>ExpamplePerson 2 </TD>
    <TD>true</TD>
</TR>
      </TABLE>
4

1 回答 1

0

按照要求:

XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="groups" match="/Objects/Object" use="concat(Property[@Name='Datum'],Property[@Name='Von'],Property[@Name='Bis'],Property[@Name='Gebucht_Von'])" />
<xsl:template match="Objects">
  <html>
  <body>
    <table border="6pt" align="center">
    <colgroup>
        <col width="150" />
        <col width="100" />
        <col width="100" />
        <col width="200" />
        <col width="500" />
    </colgroup>
    <tr style="font-size: 16pt; background-color: #E4FEFF; color: 051956; font-family: Times New Roman ', Times, serif">
        <span></span>
        <th><u><i>Date</i></u></th>
        <th><u><i>From</i></u></th>
        <th><u><i>To</i></u></th>
        <th><u><i>Room</i></u></th>
        <th><u><i>Booked by</i></u></th>
    </tr>
      <xsl:for-each select="Object[generate-id() = generate-id(key('groups', concat(Property[@Name='Datum'],Property[@Name='Von'],Property[@Name='Bis'],Property[@Name='Gebucht_Von']))[1])]">
      <tr style="font-size: 13pt; background-color: #E4FEFF; color: 051956; font-family: ARIAL">
        <td><xsl:value-of select="Property[@Name='Datum']"/></td>
        <td><xsl:value-of select="Property[@Name='Von']"/></td>
        <td><xsl:value-of select="Property[@Name='Bis']"/></td>
        <td><xsl:for-each select="key('groups', concat(Property[@Name='Datum'],Property[@Name='Von'],Property[@Name='Bis'],Property[@Name='Gebucht_Von']))">
            <xsl:sort select="Property[@Name='Raum']" />
            <xsl:value-of select="Property[@Name='Raum']" /><xsl:if test="position() != last()" ><xsl:text>, </xsl:text></xsl:if>
        </xsl:for-each></td>
        <td><xsl:value-of select="Property[@Name='Gebucht_Von']"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

输出 XSLT 输出

注意:我更新了伦敦的原始输入值之一,以确保组正常工作。

于 2013-08-14T10:57:36.863 回答