我只是想用XSL樣式表創建一個示例XML文件。問題是,當我解析這兩個文件時,我得到一個奇怪的輸出。使用XML和XSLT
這裏是XML:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="mySchema.xsl"?>
<Artists>
<Artist>
<BandName>The Cure</BandName>
<Albums>
<Album>
<AlbumTitle>Disintegration</AlbumTitle>
<Tracks>
<track>
<Title>Plain Song</Title>
<Order>1</Order>
<Lenght>
<min>5</min>
<sec>12</sec>
</Lenght>
</track>
<track>
<Title>Pictures Of You</Title>
<Order>2</Order>
<Lenght>
<min>7</min>
<sec>24</sec>
</Lenght>
</track>
</Tracks>
</Album>
<Album>
<AlbumTitle>Wish</AlbumTitle>
<Tracks>
<track>
<Title>A Letter To Elise</Title>
<Order>4</Order>
<Lenght>
<min>5</min>
<sec>14</sec>
</Lenght>
</track>
<track>
<Title>From the Edge of the Deep Green Sea</Title>
<Order>2</Order>
<Lenght>
<min>7</min>
<sec>45</sec>
</Lenght>
</track>
</Tracks>
</Album>
</Albums>
</Artist>
<Artist>
<BandName>The Pogues</BandName>
<Albums>
<Album>
<AlbumTitle>If I Should Fall from Grace with God</AlbumTitle>
<Tracks>
<track>
<Title>Fairytale of New York</Title>
<Order>1</Order>
<Lenght>
<min>2</min>
<sec>20</sec>
</Lenght>
</track>
<track>
<Title>Sit Down by the Fire</Title>
<Order>13</Order>
<Lenght>
<min>4</min>
<sec>10</sec>
</Lenght>
</track>
</Tracks>
</Album>
<Album>
<AlbumTitle>Peace And Love </AlbumTitle>
<Tracks>
<track>
<Title>Young Ned Of The Hill</Title>
<Order>3</Order>
<Lenght>
<min>2</min>
<sec>45</sec>
</Lenght>
</track>
<track>
<Title>Boat Train</Title>
<Order>11</Order>
<Lenght>
<min>2</min>
<sec>40</sec>
</Lenght>
</track>
</Tracks>
</Album>
</Albums>
</Artist>
</Artists>
,這裏是XSLT文件:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Artist">
<html>
<body>
<xsl:apply-templates select="BandName"/>
<br></br>
</body>
</html>
</xsl:template>
<xsl:template match="BandName">
<b>Found a band!</b>
</xsl:template>
</xsl:stylesheet>
當我呈現了兩下,使用Visual Studio IDE中,我可以看到XML文件如何轉化爲XHTML。輸出看起來是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<html><body><b>Found a band!</b><br /></body></html>
<html><body><b>Found a band!</b><br /></body></html>
,當我看着這個在瀏覽器中,它的罰款,但我不開心怎麼< HTML> <體> </BODY> </HTML>顯示更多那一次。我究竟做錯了什麼?
感謝 傑森
謝謝大家!所有評論都非常有幫助! – jason