Maybe its just me, but for some reason I can't seem to make one XML document display as a reformatted XML document in either Firefox or IE6.
Consider these two files:
test.xml
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="testxslt.xsl"?>
<contacts>
<contact name="Curly">
<address>Same as Moe's</address>
</contact>
<contact name="Larry">
<address>Same as Curly's</address>
</contact>
<contact name="Moe">
<address>Same as Larry's</address>
</contact>
</contacts>
testxslt.xsl
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" media-type="text/xml" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="contacts">
<root>
<xsl:for-each select="contact">
<name><xsl:value-of select="@name" /></name>
</xsl:for-each>
</root>
</xsl:template>
</xsl:transform>
The output when loading test.xml into either IE6 or Firefox (latest) is this:
This is the output I would've expected:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<name>Curly</name>
<name>Larry</name>
<name>Moe</name>
</root>
So here's what I've tried so far:
- Messing around with all the different option combinations of the <xsl:output> element
- Using <xsl:element name="name"> instead of just placing <name> in the XSL
- Not using <xsl:apply-templates /> but instead doing everything inside an <xsl:template match="/"> element
So what am I missing? Oddly enough, this transformation will work inside of .NET when using an XslCompiledTransform and saving the resultant XML file to disk. I would think that browsers would similarly output pure XML. Am I wrong, or just missing something in my XSL?
Bookmarks