Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XML/XSLT

Options
  • 04-01-2013 4:18pm
    #1
    Registered Users Posts: 119 ✭✭


    Why does my XSL Stylesheet no work :'(
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet href="xsl_stepbystep.xsl" type="text/xsl"?>

    <subjects>
    <URL>http://www.webappdev.nci/subjects</URL>
    <domain>
    <name>Web Development</name>
    <subjectEntries type="overview">
    <subjectEntry id="1" status="available">XML Introduction</subjectEntry>
    <subjectEntry id="2" status="available">XPath Travels</subjectEntry>
    <subjectEntry id="3" status="unavailable">Data Validation</subjectEntry>
    </subjectEntries>
    </domain>
    </subjects>
    <?xml version="1.0" standalone="no"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/Transform"&gt;

    <xsl:template match="/">
    <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//subjectEntries">
    <html>
    <head>
    <title>Exam</title>
    </head>

    <body>
    <h2>Available Subject Entries</h2>
    <ul>
    <xsl:for-each select="subjectEntry">
    <xsl:if test="@status = 'available'">
    <li><xsl:value-of select="self"/></li>
    </xsl:if>
    </xsl:for-each>
    </ul>
    </body>
    </html>
    </xsl:template>

    </xsl:stylesheet>


Comments

  • Registered Users Posts: 27,161 ✭✭✭✭GreeBo


    Try this:
    I refactored it a little...
    - define the head body of the html page and call your template in the body
    - dont need to loop using for-each, just let the template match each subject element
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    	<xsl:template match="/">
    		<html>
    			<head>
    				<title>Exam</title>
    			</head>
    			<body>
    				<h2>Available Subject Entries</h2>
    				<xsl:apply-templates/>
    			</body>
    		</html>
    	</xsl:template>
    
    	<xsl:template match="subjectEntry">
    		<xsl:if test="@status = 'available'">
    			<ul> 
    				<li><xsl:value-of select="."/></li>
    			</ul>
    		</xsl:if>
    	</xsl:template>
    </xsl:stylesheet>
    


  • Registered Users Posts: 119 ✭✭Stamply


    Cheers buddy :-)

    I still don't know why my one was broken, but I can see how yours was better...


  • Registered Users Posts: 795 ✭✭✭tawfeeredux


    Stamply wrote: »
    I still don't know why my one was broken...

    Change your namespace URI to:
    <..."http://www.w3.org/1999/XSL/Transform">


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    Stamply wrote: »
    Cheers buddy :-)

    I still don't know why my one was broken, but I can see how yours was better...

    Does it say where it failed? Is anything showing up?

    Could change
    <xsl:for-each select="subjectEntry">
    

    to
    <xsl:for-each select="./subjectEntry">
    


  • Registered Users Posts: 7,838 ✭✭✭Nulty


    Yeah. The capitalised "XSL" made most of the problems but the subjectEntry matches worked when changing "self" to "."


  • Advertisement
Advertisement