我正在輸出我的XSLT爲HTML,但是我已經閱讀過,因爲驗證原因XML更好。因此,當我將輸出從HTML更改爲XML時,它將會破壞頁面,這是否意味着我需要現在從XSLT文件中刪除所有HTML元素?我也通過外部CSS文件進行樣式設置,當輸出爲XML時,樣式是否需要位於XSLT文件中?如何在XSLT中正確使用輸出爲XML?
這裏是我的網頁代碼:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
doctype-system="http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"
doctype-public="-//WAPFORUM//DTD XHTML Mobile 1.2//EN" />
<xsl:template match="/">
<xsl:element name="head">
<xsl:element name="title">Selected Flight Route</xsl:element>
<link rel="stylesheet" type="text/css" href="mystyles.css" title="Style"/>
</xsl:element>
<xsl:element name="body">
<xsl:element name="div"><!-- This holds the navigation bar-->
<xsl:attribute name="id">
<xsl:text>navdiv</xsl:text>
</xsl:attribute>
<xsl:element name="div"><!-- This holds the image links-->
<xsl:attribute name="id">
<xsl:text>navlinks</xsl:text>
</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="id">
<xsl:text>navlinksone</xsl:text>
</xsl:attribute>
<xsl:attribute name="href">flights.php</xsl:attribute>
</xsl:element>
<xsl:element name="a">
<xsl:attribute name="id">
<xsl:text>navlinkstwo</xsl:text>
</xsl:attribute>
<xsl:attribute name="href">planes.php</xsl:attribute>
</xsl:element>
<xsl:element name="a">
<xsl:attribute name="id">
<xsl:text>navlinksthree</xsl:text>
</xsl:attribute>
<xsl:attribute name="href">weatherfeed.php</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element><!-- End the navigation bar-->
<xsl:element name="div"><xsl:attribute name="id">
<xsl:text>maindiv</xsl:text>
</xsl:attribute>
<h1 id="heading">Flights and planes</h1>
<xsl:element name="div"><xsl:attribute name="id">
<xsl:text>divone</xsl:text>
</xsl:attribute><img width="30" height="30" src="globe.png"/><p class="centerp">Selecting the Globe will display all flight routes.</p></xsl:element>
<xsl:element name="div"><xsl:attribute name="id">
<xsl:text>divtwo</xsl:text>
</xsl:attribute><img width="75" height="30" src="planepic.png"/><p class="centerp">Selecting the Plane will display all Aircraft info.</p></xsl:element>
<xsl:element name="div"><xsl:attribute name="id">
<xsl:text>divthree</xsl:text>
</xsl:attribute><img width="32" height="30" src="weather.png"/><p class="centerp">The Weather icon displays the weather in all citys.</p></xsl:element>
</xsl:element>
</xsl:element>
<!-- End the Body element -->
</xsl:template>
<!-- End the Main Template element -->
</xsl:stylesheet>
Here是鏈接到頁面的輸出格式爲XML,並here是作爲HTML輸出相同的頁面,任何人都可以告訴我這是爲什麼輸出爲XML時弄亂了我的頁面?在研究發現問題時,我注意到以XML格式輸出的示例文件似乎沒有任何HTML元素。
下面是我用轉換XML的原始文件:
謝謝你,我一直在做這個,我只是想通了這是造成問題,因爲我正在開發移動網站的文檔類型,當我使用一個移動Doctype它把頁面擰緊。你知道我如何在我的XSLT中使用移動XHTML Doctype嗎?謝謝!我試圖在這個頁面上使用其中的一個http://mobiforge.com/testing/story/fixit-xhtml-mobile-profile – deucalion0 2013-02-28 14:46:13
嗯,我從來沒有使用過XHTML手機,但我不太瞭解它,但是你可以閱讀這些文章/片段的第二部分:http://www.xml.com/pub/a/2004/04/14/mobile.html在那裏,他們只是使用外部DTD。希望它有幫助 – 2013-02-28 14:50:42
感謝您的幫助,我已經嘗試過所有類型的移動DTD,沒有任何工作。當我使用XHTML嚴格的DTD時,我的頁面加載正常並且所有內容都是有效的,但是當我使用移動DTD時,它會將其全部解決,我不知道爲什麼。移動DTD和XSLT似乎沒有太多信息!我會繼續讀! – deucalion0 2013-02-28 15:05:40