tags:

views:

46

answers:

3

Below is the input xml :

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="value-of.xsl"?>
<MemeberDetails>
    <Employee>
        <Name>Madhu</Name>
        <Sex>Male</Sex>
        <DOB>2/10/1982</DOB>
        <Address>JP Nagar ,Bangalore</Address>
        <MemberId>094631</MemberId>
        <Designation>SSE</Designation>
        <Department>SG</Department>
    </Employee>
</MemeberDetails>

where, i am referring value-of.xsl file using HREF in above xml. and this file is residing in same folder.

Below is the value-of.xslt file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <CGIEmployeeDetails>
            <PersonalDetails>
                <Name>
                    <xsl:value-of select="/MemeberDetails/Employee/Name"/>
                </Name>
                <Gender>
                    <xsl:value-of select="/MemeberDetails/Employee/Sex"/>
                </Gender>
                <ResidentialAddress>
                    <xsl:value-of select="/MemeberDetails/Employee/Address"/>
                </ResidentialAddress>
            </PersonalDetails>
            <WorkingDetails>
                <PSAID>
                    <xsl:value-of select="//MemberId"/>
                </PSAID>
                <Designation>
                    <xsl:value-of select="/MemeberDetails/Employee/Designation"/>
                </Designation>
                <Department>
                    <xsl:value-of select="/MemeberDetails/Employee/Department"/>
                </Department>
            </WorkingDetails>
        </CGIEmployeeDetails>
    </xsl:template>
</xsl:stylesheet>

When i run above xml in browser , the output will result as text but not as XML . If i use editor like Oxygen and transform the same xml file , the output will be XML.

I am not getting why browser is failing to transform a XML output ? Is there anything to do with browser ?

A: 

Are you using internet explorer? That is the only browser I know of that would completely ignore your XSL stylesheet

Razor
Yes i am using IE8 and Firefox too . So, there is no way i can see output as XML in browser other than using IDE?
Madhu CM
Firefox should work just fine. If you cannot see the correct output there, it means there's an error - verify that the file is accessible. If you want this to work in IE8 you'll have to look in a server side solution doing the transformation tho.
Razor
@Razor , i see no error in transformation. I can see proper output in Oxygen Editor , thanks.
Madhu CM
+2  A: 

In browsers, the "XML format" view is mostly a stylesheet adding syntax highlighting and Emacscript event handlers (show and hide chlids nodes, etc.).

So, when the document has a XSLT stylesheet PI, browsers don't run that "XML format" stylesheet but they try to render the transformation result. This intent is not the same for each browser. Only one thing is guaranteed: if it's proper XHTML or HTML, is render as is.

If the transformation result is not proper XHTML nor HTML (plain text, other XML vocabulary), the render mechanism varies from one to another: i.e Chrome is the only one showing nothing for unknown XML vocabulary, others render this as HTML anyway (rendering only text).

Alejandro
A: 

@Alejandro provided a good explanation.

Using IE, you can see the result of the XSLT transformation by right-clicking on the IE window and selecting "View Source"

Dimitre Novatchev
@Dimitre: Actualy, IE doesn't do that. You need to have the old "Transformation Viewer" plug-in or to use the Developer Bar. Other browser have the built-in "Inspect element", but again for Chrome it shows nothing with unknow vocabulary.
Alejandro
@Alejandro: I did this yesterday. I have IE8.
Dimitre Novatchev
@Dimitre: The "View Source" option should show you the incomming XML document before transformation (the source). In IE8 you can use built-in "Developer Tools" for seeing transformation result DOM. I just have tested with my XML/XSLT driven [site](http://www.aranedabienesraices.com.ar)
Alejandro