Embedding XSL Styles in 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 renders the XML as if the XSL line is missing. Do you know why the browser ignores the XSL stylesheet? Invalid style sheet?

thank

+3


source to share


4 answers


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 is not a well-formed XML document (no top elements are present), so it should come as no surprise that the browser doesn't treat it as such.

Decision

Update your "XML" to a really well-formed XML document, for example:

<?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 conversion result :

XXX

+2


source


It looks like you are not closing one of your tags for each one?



0


source


the cycle is xsl:for-each

select="rss/channel/item"

not closed.

0


source


This could be the same origin policy as security restrictions. If your XML and XSLT are not co-located, the browser can opt out of using XSLT and apply it to your XML file.

0


source







All Articles