Click to See Complete Forum and Search --> : <xsl:output> problems


bogocles
06-30-2008, 02:01 PM
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

<?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

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

CurlyLarryMoe

This is the output I would've expected:


<?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?

bogocles
07-09-2008, 11:16 AM
I hope you guys can forgive me, but I'm bumping this a single time for some help.

Kostas Zotos
07-28-2008, 01:03 PM
Hi,

Your code is OK,

The result you get is:

<root>
<name>Curly</name>
<name>Larry</name>
<name>Moe</name>
</root>

-----------------

I tested it in the browser (Netscape and FireFox) and when see the source code you, will get the initial .xml file (at least in my case), also the output is the text values of the previous 3 elements thus: CurlyLarryMoe.. However if you could see the render code it has the form shown above (the xml tree you expect)

Example when save the page as HTML from netscape and open the source to see the html the results are what expected.. still when open the html page i only see the 3 names..

If also run the .xsl through php I get the correct result (the xml tree)..

Cheers!

Kostas