我是 XSL 的新手,试图为我做一些有点复杂的事情,并寻求帮助。
下面是 XML 的示例:
<foo>
<customers>
<customer>
<title>Ms</title>
<name>
<firstName>Jane</firstName>
<lastName>Customer</lastName>
</name>
<reservations>
<reseration>
<reservationNumber>123</reservationNumber>
<reservationDate>2013-02-15</reservationDate>
<table>12</table
</reservation>
<reseration>
<reservationNumber>456</reservationNumber>
<reservationDate>2013-03-24</reservationDate>
<table>09</table
</reservation>
<reseration>
<reservationNumber>789</reservationNumber>
<reservationDate>2013-05-02</reservationDate>
<table>22</table
</reservation>
</reservations>
</customer>
<customer>
<title>Dr</title>
<name>
<firstName>John</firstName>
<lastName>Smith</lastName>
</name>
<reservations>
<reseration>
<reservationNumber>ABC</reservationNumber>
<reservationDate>2013-02-15</reservationDate>
<table>05</table
</reservation>
<reseration>
<reservationNumber>DEF</reservationNumber>
<reservationDate>2013-03-24</reservationDate>
<table>10</table
</reservation>
<reseration>
<reservationNumber>GHI</reservationNumber>
<reservationDate>2013-05-02</reservationDate>
<table>16</table
</reservation>
</reservations>
</customer>
</customers>
</foo>
我希望结果表如下所示:
Title Name Reservation Date Table
----- ---- ----------- ---- -----
Ms Jane Customer 123 2013-02-15 12
456 2013-03-24 09
789 2013-05-02 22
Dr John Smith ABC 2013-02-15 05
DEF 2013-03-24 10
GHI 2013-05-02 16
我知道如何使用 XSL for-each 来构建每一行。棘手的是如何构建递归,它将第一个子元素中的预订详细信息(预订、日期和表格)拉到与第一行的父元素相同的行中。然后只有剩余行中剩余子元素的保留详细信息。
所以这:
Title Name Reservation Date Table
----- ---- ----------- ---- -----
Ms Jane Customer 123 2013-02-15 12
456 2013-03-24 09
789 2013-05-02 22
不是这个:
Title Name Reservation Date Table
----- ---- ----------- ---- -----
Ms Jane Customer
123 2013-02-15 12
456 2013-03-24 09
789 2013-05-02 22
做了很多搜索,并没有看到类似的东西。
更新
这是我能够开始工作的地方
<xsl:for-each select="customers/customer">
<xsl:for-each select="./reservations/reservation">
<xsl:choose>
<xsl:when test="position() = 1">
<tr>
<td><xsl:value-of select="../../title"/></td>
<td><xsl:value-of select="reservationNumber"/></td>
</tr>
</xsl:when>
....