【发布时间】:2013-08-15 23:40:36
【问题描述】:
我之前问过这个问题,但我会尝试更详细地解释我的问题。我从一个用户可以预订房间的系统中获取了一个 XML(实际的 XML 比我的例子大得多)。这些房间用于从一个城市到另一个城市的交流。 因此,如果一个人想预订,他必须至少预订 2 个房间。我创建了一个表格,以便其他用户可以看到谁在什么日期/时间预订了哪个房间。
table(这里还不能上传图片) 如您所见,表格不是很清楚。它有很多不需要的相同值。所以我想要的是我只有一个日期和时间以及每个预订的一个名字。但房间必须至少有 2 间相同才能获得更好的视野。 在我的 xslt 中你还可以看到尝试在测试中获取一组节点
你能帮忙吗?
<?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 样式表
<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>
这就是我想要输出的内容
<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>
【问题讨论】:
-
而不是链接到带有弹出式广告的网站,它会遮盖您要显示的表格,您能否修改问题以在这种情况下显示您要输出的 HTML ?另外,顺便问一下,您使用的是 XSLT 1.0 还是 XSLT 2.0?这看起来像是一个分组问题,并且在 XSLT 2.0 中分组的处理方式不同。谢谢!
-
我编辑了它。谢谢你的提示。我需要使用 xslt 1.0