www.webdeveloper.com
Results 1 to 3 of 3

Thread: <xsl:output> problems

  1. #1
    Join Date
    Oct 2007
    Location
    USA
    Posts
    73

    <xsl:output> problems

    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:

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

  2. #2
    Join Date
    Oct 2007
    Location
    USA
    Posts
    73
    I hope you guys can forgive me, but I'm bumping this a single time for some help.

  3. #3
    Join Date
    Mar 2007
    Location
    Athens, Greece
    Posts
    177
    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
    Last edited by Kostas Zotos; 07-28-2008 at 01:05 PM.
    K. Zotos online portfolio (3D, Web, Programming): http://www.in3d.eu/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles