Akhil Biju
Akhil Biju

Reputation: 33

XML - XSL not working

The styles i have mentioned in the XSL is not applying to the XML. The is the output i am getting output on mozilla firefox

This is the XSL code

    <?xml version = "1.0"?> 
    <xsl:stylesheet version = "1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" 
    xmlns = "http://www.w3.org/TR/xhtml1/strict"> 
    <xsl:template match = "/"> 
    <h2> Student information </h2> 
    <xsl:for-each select="student">
    USN:<span style = "font-style: italic;color:red">
    <xsl:value-of select = "USN" /><br /></span> 
    Name:<span style = "font-style: italic"> 
    <xsl:value-of select = "name" /><br /></span> 
    college Name:<span style = "font-style: italic;color:green"> 
    <xsl:value-of select = "college" /><br /></span>
    Branch:<span style = "font-style: italic;color:blue"> 
    <xsl:value-of select = "branch" /><br /></span> 
    Year of Joining:<span style = "font-style: italic;color:yellow"> 
    <xsl:value-of select = "YOJ" /><br /></span> 
    Email-id:<span style = "font-style: italic;color:blue"> 
    <xsl:value-of select = "email" /><br /></span> 
    </xsl:for-each> 
    </xsl:template> 
    </xsl:stylesheet>  

And here is the XML code

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="info.xsl"?> 
<student> 
<USN> 4PM10CS020 </USN> 
<name> John Doe </name>
<college> PESITM, Shivamogga. </college>
<branch> CSE </branch> 
<YOJ> 2010 </YOJ> 
<email> [email protected] </email> 
</student>  

What am i doing wrong ?

Upvotes: 0

Views: 420

Answers (1)

ScanQR
ScanQR

Reputation: 3820

It all depends on what out method you choose during transformation. In following I have defined output method as xml, it will give you output as XML which then you can render. Alternatively try with output method as html

Find follwoing working XSL.

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://locomotive/bypass/docx" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="node()">
    <xsl:copy>
        <xsl:apply-templates select="node()"/>
    </xsl:copy>
</xsl:template>

   <xsl:template match="/">
        <h2> Student information </h2>
        <xsl:for-each select="student">
            USN:
            <span style="font-style: italic;color:red">
                <xsl:value-of select="USN" />
                <br />
            </span>
            Name:
            <span style="font-style: italic">
                <xsl:value-of select="name" />
                <br />
            </span>
            college Name:
            <span style="font-style: italic;color:green">
                <xsl:value-of select="college" />
                <br />
            </span>
            Branch:
            <span style="font-style: italic;color:blue">
                <xsl:value-of select="branch" />
                <br />
            </span>
            Year of Joining:
            <span style="font-style: italic;color:yellow">
                <xsl:value-of select="YOJ" />
                <br />
            </span>
            Email-id:
            <span style="font-style: italic;color:blue">
                <xsl:value-of select="email" />
                <br />
            </span>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Workgin demo for you : http://xsltransform.net/ejivdHb/25

enter image description here

Upvotes: 1

Related Questions