Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XML/XSLT

  • 04-01-2013 04:18PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 27,517 ✭✭✭✭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, Registered Users 2 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, Registered Users 2, Paid Member Posts: 817 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 7,838 ✭✭✭Nulty


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


  • Advertisement
Advertisement