1

我一直试图让这个 xsl 转换在我的 php 中运行 xsl 运行正常,但它不输出 for-each 部分的值我得到所有标题,但我似乎无法得到它在这里输出任何其他内容就是 curl XML 响应的样子:

<search>
<response status="2">
<errors>
 StartdateEarlierThanToday0Incorrect start date. Start date cannot be earlier than today.0FalseFalse
 </errors>
<number_of_hotels>1 of 1</number_of_hotels>
</response>
<lr_rates>
<hotel>
 <hotel_ref>142680</hotel_ref>
 <hotel_currency>GBP</hotel_currency>
 <hotel_rooms>
  <room>
  <ref>4380316</ref>
 <type>10</type>
 <type_description>Apartment</type_description>
 <sleeps>2</sleeps>
 <rooms_available>0</rooms_available>
 <adults>2</adults>
 <children>0</children>
 <breakfast>false</breakfast>
 <dinner>false</dinner>
 <description>
 The apartment has seperate kitchen area, lounge/dining area, bedroom with double bed and bathroom with bath & shower.
 </description>
 <alternate_description/>
 <rack_rate>140.00</rack_rate>
 <rate>
 <date>01/08/2012</date>
 <formatted_date>01 August 2012</formatted_date>
 <price>Full</price>
 <hotelcurrencyprice>Full</hotelcurrencyprice>
 <numeric_price>Full</numeric_price>
 <numeric_hotelcurrencyprice>Full</numeric_hotelcurrencyprice>
  <requested_currency>GBP</requested_currency>
  </rate>
    <rate>
   <date>02/08/2012</date>
   <formatted_date>02 August 2012</formatted_date>
    <price>Full</price>
    <hotelcurrencyprice>Full</hotelcurrencyprice>
    <numeric_price>Full</numeric_price>
     <numeric_hotelcurrencyprice>Full</numeric_hotelcurrencyprice>
     <requested_currency>GBP</requested_currency>
     </rate>
     <available_online>false</available_online>
    <minimum_nights>1</minimum_nights>
   <bed_type>Double</bed_type>
   <cancellation_policy/>
   <cancellation_days/>
   <cancellation_hours/>
   <room_terms/>
  </room>
 <room>...</room>
 </hotel_rooms>
 </hotel>
 </lr_rates>
 </search>

那么这是要使用的 xsl im tryig

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h2>Availability Search:</h2>
<table border="1">
  <tr bgcolor="#FFFFFF">
    <th align="left">Room Type</th>
    <th align="left">Description</th>
    <th align="left">Availability</th>
    <th align="left">Price</th>
   </tr>
  <xsl:for-each select="/">
    <tr>
     <td><xsl:value-of select="type_description" /></td>
     <td><xsl:value-of select="description" /></td>
     <td><xsl:value-of select="rooms_available" /></td>
     <td><xsl:value-of select="rack_rate" /></td>
    </tr>
   </xsl:for-each>
 </table>
</xsl:template>
</xsl:stylesheet>
4

1 回答 1

2

这是你的问题:

<xsl:for-each select="/">
    <tr>
        <td>
            <xsl:value-of select="type_description" />
        </td>
        <td>
            <xsl:value-of select="description" />
        </td>
        <td>
            <xsl:value-of select="rooms_available" />
        </td>
        <td>
            <xsl:value-of select="rack_rate" />
        </td>
    </tr>
</xsl:for-each>

这仅处理一个节点——文档节点/,并且因为它没有名为type_descriptionor descriptionor rooms_availableor的子节点rack_rate ——没有任何输出。

如果没有时间仔细观察,您可能需要以下内容:

<xsl:for-each select="/*/lr_rates/hotel/hotel_rooms/room">
    <tr>
        <td>
            <xsl:value-of select="type_description" />
        </td>
        <td>
            <xsl:value-of select="description" />
        </td>
        <td>
            <xsl:value-of select="rooms_available" />
        </td>
        <td>
            <xsl:value-of select="rack_rate" />
        </td>
    </tr>
</xsl:for-each>
于 2012-08-01T13:54:03.367 回答