[英]XSLT not working with my XML
Hi my XSL doesn't seem to be working with my XML. 嗨,我的XSL似乎不适用于我的XML。 I can't seem to figure out the problem even though my code is quite simple. 即使我的代码很简单,我似乎也无法解决问题。 My XML sheet seems to transform into just raw Data when i link to the XSL spreadsheet and open the document. 当我链接到XSL电子表格并打开文档时,我的XML工作表似乎变成了原始数据。
My XSL 我的XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Room Information</title>
</head>
<body>
<h1>Room information</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>TITLE</th>
<th>ACCOMODATION</th>
<th>COST</th>
<th>LEVEL</th>
<th>VIEW</th>
<th>ENSUITE</th>
<th>MAID_SERVICE</th>
<th>ROOM_SERVICE</th>
<th>LAUNDRY_SHOOT</th>
<th>ROOM_IMAGE</th>
<th>PAST_CUSTOMERS</th>
</tr>
<xsl:for-each select="ROOMS/ROOM">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ACCOMODATION"/></td>
<td><xsl:value-of select="COST"/></td>
<td><xsl:value-of select="LEVEL"/></td>
<td><xsl:value-of select="VIEW"/></td>
<td><xsl:value-of select="ENSUITE"/></td>
<td><xsl:value-of select="MAID_SERVICE"/></td>
<td><xsl:value-of select="ROOM_SERVICE"/></td>
<td><xsl:value-of select="LAUNDRY_SHOOT"/></td>
<td><xsl:value-of select="ROOM_IMAGE"/></td>
<td><xsl:value-of select="PAST_CUSTOMERS"/></td>
</tr>
</xsl:for-each>
This is my XML (The DTD can just be ignored) 这是我的XML(DTD可以忽略)
?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XSL/RoomsXSL.xsl"?>
<!DOCTYPE ROOMS [
<!ELEMENT ROOM (TITLE+,ACCOMODATION,COST,LEVEL+,VIEW,ENSUITE,MAID_SERVICE,ROOM_SERVICE,LAUNDRY_SHOOT,ROOM_IMAGE+,PAST_CUSTOMERS+)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT ACCOMODATION (#PCDATA)>
<!ELEMENT COST (#PCDATA)>
<!ELEMENT LEVEL (#PCDATA)>
<!ELEMENT VIEW (#PCDATA)>
<!ELEMENT ENSUITE (#PCDATA)>
<!ELEMENT MAID_SERVICE (#PCDATA)>
<!ELEMENT ROOM_SERVICE (#PCDATA)>
<!ELEMENT LAUNDRY_SHOOT (#PCDATA)>
<!ELEMENT ROOM_IMAGE (#PCDATA)>
<!ELEMENT PAST_CUSIMERS (#PCDATA)>
<!ENTITY writer "Dylan Weiss">
<!ENTITY copyright "Horizon BnB">
]>
<ROOMS>
<ROOM id="01">
<TITLE>Top Floor 1</TITLE>
<ACCOMODATION>Accomodates 2 people</ACCOMODATION>
<COST>$700 a week.$120 every day over a week</COST>
<LEVEL>Top floor</LEVEL>
<VIEW>Includes panoramic View</VIEW>
<ENSUITE>Has ensuite</ENSUITE>
<MAID_SERVICE>Maid service included</MAID_SERVICE>
<ROOM_SERVICE>Includes room service</ROOM_SERVICE>
<LAUNDRY_SHOOT>Includes laundry shoot</LAUNDRY_SHOOT>
<ROOM_IMAGE>Images/LuxuryRoom1.jpg</ROOM_IMAGE>
<PAST_CUSTOMERS>WWW.Horizon/PastCustomers.com</PAST_CUSTOMERS>
</ROOM>
<ROOM id="02">
<TITLE>Bottom floor 1</TITLE>
<ACCOMODATION>Accomodates 2 people</ACCOMODATION>
<COST>$500 a week.$100 every day over a week</COST>
<LEVEL>Ground floor</LEVEL>
<VIEW>Includes a courtyard</VIEW>
<ENSUITE>Has ensuite</ENSUITE>
<MAID_SERVICE>Maid service included</MAID_SERVICE>
<ROOM_SERVICE>Includes room service</ROOM_SERVICE>
<LAUNDRY_SHOOT>No laundry shoot</LAUNDRY_SHOOT>
<ROOM_IMAGE>Images/LuxuryRoom1.jpg</ROOM_IMAGE>
<PAST_CUSTOMERS>WWW.Horizon/PastCustomers.com</PAST_CUSTOMERS>
</ROOM>
<ROOM id="03">
<TITLE>Bottom floor 2</TITLE>
<ACCOMODATION>Accomodates 4 people</ACCOMODATION>
<COST>$800 a week.$120 every day over a week</COST>
<LEVEL>Ground floor</LEVEL>
<VIEW>Includes a courtyard</VIEW>
<ENSUITE>Has ensuite</ENSUITE>
<MAID_SERVICE>Maid service included</MAID_SERVICE>
<ROOM_SERVICE>Includes room service</ROOM_SERVICE>
<LAUNDRY_SHOOT>No laundry shoot</LAUNDRY_SHOOT>
<ROOM_IMAGE>Images/LuxuryRoom1.jpg</ROOM_IMAGE>
<PAST_CUSTOMERS>WWW.Horizon/PastCustomers.com</PAST_CUSTOMERS>
</ROOM>
</ROOMS>
I'd suggest using matching templates instead of your for-each: Your root template will pull the matching ROOMS
template which in turn will pull the matching ROOM
. 我建议使用匹配的模板而不是for-each:您的根模板将提取匹配的ROOMS
模板,而模板又将提取匹配的ROOM
。
<xsl:apply-template />
will take care to fetch the matching template at the desired position. <xsl:apply-template />
将注意在所需位置获取匹配的模板。
If you ever need to hide an element, just declare an empty template: <xsl:template match="ROOM" />
. 如果您需要隐藏元素,只需声明一个空模板: <xsl:template match="ROOM" />
。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Room Information</title>
</head>
<body>
<h1>Room information</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>TITLE</th>
<th>ACCOMODATION</th>
<th>COST</th>
<th>LEVEL</th>
<th>VIEW</th>
<th>ENSUITE</th>
<th>MAID_SERVICE</th>
<th>ROOM_SERVICE</th>
<th>LAUNDRY_SHOOT</th>
<th>ROOM_IMAGE</th>
<th>PAST_CUSTOMERS</th>
</tr>
<xsl:apply-templates />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="ROOMS">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ROOM">
<tr>
<td>
<xsl:value-of select="TITLE"/>
</td>
<td>
<xsl:value-of select="ACCOMODATION"/>
</td>
<td>
<xsl:value-of select="COST"/>
</td>
<td>
<xsl:value-of select="LEVEL"/>
</td>
<td>
<xsl:value-of select="VIEW"/>
</td>
<td>
<xsl:value-of select="ENSUITE"/>
</td>
<td>
<xsl:value-of select="MAID_SERVICE"/>
</td>
<td>
<xsl:value-of select="ROOM_SERVICE"/>
</td>
<td>
<xsl:value-of select="LAUNDRY_SHOOT"/>
</td>
<td>
<xsl:value-of select="ROOM_IMAGE"/>
</td>
<td>
<xsl:value-of select="PAST_CUSTOMERS"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.