简体   繁体   中英

Embedding XSL Stylesheet into XML

I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="http://www.fakedomain.com/sally.xsl"?>

And the following content in sally.xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="documentcollection/document">
<p>
<xsl:for-each select="rss/channel/item">
<xsl:value-of select="title"/><br />
<xsl:value-of select="description"/><br />
<xsl:value-of select="link"/><br />
</xsl:for-each>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

However, the browser displays the XML as though the XSL line is not present. Do you know why the browser is ignoring the XSL stylesheet? Is the style sheet wrong?

Thanks

I have the following XML:

 <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="http://www.fakedomain.com/sally.xsl"?> 

This isn't a well-formed XML document (no top element present), so it isn't much of a surprize the browser doesn't treat it as such.

Solution :

Update your "XML" to a really well-formed XML document, something like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="file:///c:/temp/delete/xxx.xsl"?>
<t/>

With this stylesheet in c:\\temp\\delete\\xxx.xsl :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
     XXX
 </xsl:template>
</xsl:stylesheet>

when the XML file is opened with IE, the browser displays the result of the transformation :

XXX

看起来你没有关闭你的每个标签之一?

select="rss/channel/item"xsl:for-each循环未关闭。

It could be same origin policy security restrictions. If your XML and XSLT are not hosted in the same location, then the browser may be refusing to fetch the XSLT and apply it to your XML file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM