我的 XML 文件:
<result>
<xml_acc>
<CheckInFrom>01:15</CheckInFrom>
<CheckInTo>00:30</CheckInTo>
<CheckOutFrom>00:45</CheckOutFrom>
<CheckOutTo>01:15</CheckOutTo>
<hotel_id>1</hotel_id>
<name>Tahir Hotel</name>
<hoteltype>Tahir Hotel</hoteltype>
<CityID>1</CityID>
<city>London</city>
<CountryID>26</CountryID>
<CurrencyId>26</CurrencyId>
<languagecode>1</languagecode>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</xml_acc>
<xml_acc>
<CheckInFrom>01:15</CheckInFrom>
<CheckInTo>00:30</CheckInTo>
<CheckOutFrom>00:45</CheckOutFrom>
<CheckOutTo>01:15</CheckOutTo>
<hotel_id>1</hotel_id>
<name>Tahir Hotel</name>
<hoteltype>Tahir Hotel</hoteltype>
<CityID>1</CityID>
<city>London</city>
<CountryID>26</CountryID>
<CurrencyId>26</CurrencyId>
<languagecode>1</languagecode>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</xml_acc>
</result>
我正在申请以下 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="html" />
<xsl:strip-space elements="*"/>
<xsl:template match="xml_acc">
<result>
<!--<xsl:apply-templates select="node()[not(self::CheckInTo) and not(self::CheckInFrom)][not(self::CheckOutTo) and not(self::CheckOutFrom)]"/>-->
<Address>
<xsl:apply-templates select="Address"/>
</Address>
<checkin>
<from>
<xsl:apply-templates select="CheckInTo"/>
</from>
<to>
<xsl:apply-templates select="CheckInFrom"/>
</to>
</checkin>
<city>
<xsl:apply-templates select="city"/>
</city>
<city_id>
<xsl:apply-templates select="CityID"/>
</city_id>
<Location>
<Latitude>
<xsl:apply-templates select="Latitude"/>
</Latitude>
<Longitude>
<xsl:apply-templates select="Longitude"/>
</Longitude>
</Location>
<city_id>
<xsl:apply-templates select="CityID"/>
</city_id>
<max_persons_in_reservation>
<xsl:apply-templates select="max_persons_in_reservation"/>
</max_persons_in_reservation>
<name>
<xsl:apply-templates select="name"/>
</name>
<ranking>
<xsl:apply-templates select="ranking"/>
</ranking>
<url>
<xsl:apply-templates select="url"/>
</url>
<zip>
<xsl:apply-templates select="zip"/>
</zip>
</result>
</xsl:template>
</xsl:stylesheet>
我得到了结果:
<result>
<Address>
</Address>
<checkin>
<from>00:30</from>
<to>01:15</to>
</checkin>
<city>London</city>
<city_id>1</city_id>
<Location>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
</Location>
<city_id>1</city_id>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<name>Tahir Hotel</name>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</result>
<result>
<Address></Address>
<checkin>
<from>00:30</from>
<to>01:15</to>
</checkin>
<city>London</city>
<city_id>1</city_id>
<Location>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
</Location>
<city_id>1</city_id>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<name>Tahir Hotel</name>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</result>
我的 XSLT 正在生成带有多个根标记的 XML。我希望应该有一个根元素,并且在这个标签中应该出现多个标签。我想要这样的结果:
<hotels>
<result>
<Address>
</Address>
<checkin>
<from>00:30</from>
<to>01:15</to>
</checkin>
<city>London</city>
<city_id>1</city_id>
<Location>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
</Location>
<city_id>1</city_id>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<name>Tahir Hotel</name>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</result>
<result>
<Address></Address>
<checkin>
<from>00:30</from>
<to>01:15</to>
</checkin>
<city>London</city>
<city_id>1</city_id>
<Location>
<Latitude>13131313</Latitude>
<Longitude>11131131</Longitude>
</Location>
<city_id>1</city_id>
<max_persons_in_reservation>1000</max_persons_in_reservation>
<name>Tahir Hotel</name>
<ranking>1</ranking>
<url>123Testing</url>
<zip>W2 6DX</zip>
</result>
</hotels>
请帮我解决这个问题。我创建了一个测试页面,您可以通过将此处的粘贴文本复制到我的页面来检查您的建议。下面是测试代码的链接: