我正在输出我的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