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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

XML/XSLT

  • 04-01-2013 3: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,370 ✭✭✭✭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 Posts: 806 ✭✭✭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