Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee 1130 posts 3088 karma points
    Jul 16, 2009 @ 16:35
    Lee
    0

    Struggling With Syntax

    Probably pretty simple, but I have a doctype that has a propertie called ShowInFooter with a type of True/False. I'm trying to create a macro that would find any documents with this propertie set to true and display them in a list.  I'm not getting any errors in my XSLT but its just not returning any documents when I know there is at least 1 with it set to true

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">
    <xsl:output method="xml" omit-xml-declaration="yes" />
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- The fun starts here -->
    <ul id="footer">
    <xsl:for-each select="$currentPage/ancestor::node/descendant-or-self::node">
    <xsl:if test="$currentPage/node [string(data [@alias='ShowInFooter']) = '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>

    Any help very appreciated as to where I am going wrong

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jul 16, 2009 @ 16:38
    Sebastiaan Janssen
    0

    Try this:

    <xsl:if test="boolean($currentPage/data[@alias='ShowInFooter'])">
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 16, 2009 @ 16:39
    Warren Buckley
    0

    OK the first thing is to change your xsl:if $currentPage refers to the currentpage you are on and not the current item in the for-each loop.

    So change

    <xsl:if test="$currentPage/node [string(data [@alias='ShowInFooter']) = '1']">

    to

     

    <xsl:if test="current()/[string(data [@alias='ShowInFooter']) = '1']">

    or which should do the same thing

    <xsl:if test="[string(data [@alias='ShowInFooter']) = '1']">
  • Lee 1130 posts 3088 karma points
    Jul 16, 2009 @ 16:51
    Lee
    0

    Thanks chaps, help very appreciated

    @Warren - I tried both but get this error?

    System.Xml.Xsl.XslLoadException: Unexpected token '[' in the expression.
    

    @Sebastiaan - I added yours and it saved but still returns nothing?  I have triple checked and the property is called 'ShowInFooter' and I have one document ticked as 'Yes' in the UI so I can't understand why it won't show!

    Just checking my select does go all the way to the root and then back down? So it does check all documents?

  • Ron Brouwer 273 posts 768 karma points
    Jul 16, 2009 @ 16:59
    Ron Brouwer
    0

    <xsl:if test="$currentPage/node[string(data[@alias='ShowInFooter']) = '1']">

    Check in data/umbraco.config if the data is saved as expected.

    You can also add this xpath condition to the xsl:foreach for better performance.

    Ron

     

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jul 16, 2009 @ 17:01
    Sebastiaan Janssen
    1

    Ah yes, I forgot you were already in a loop, so this should work a bit better:

    <xsl:if test="boolean(data[@alias='ShowInFooter'])">
  • Chris Dunn 210 posts 401 karma points
    Jul 16, 2009 @ 17:04
    Chris Dunn
    1

    Lee,

    Remove the surrounding '[' and ']' from the condition in warren's 2nd example.

    <xsl:if test="string(data [@alias='ShowInFooter']) = '1'">

    -Chris

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 16, 2009 @ 17:08
    Warren Buckley
    100

    Sorry as Chris mentions it should be like this.

    <xsl:if test="string(data [@alias='ShowInFooter']) = '1'">
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 16, 2009 @ 17:09
    Warren Buckley
    0

    Oops sorry didnt read properly. Chris had already given you the example. Im getting tired time to sign off for today !

  • Lee 1130 posts 3088 karma points
    Jul 16, 2009 @ 17:29
    Lee
    0

    Man I thought this would be so easy!  I really trying to stick with XSLT but I could do this with a lines of code in ASP.NET!! :(

    Anyway... Still not working :(

    @Ron -Tried yours and its not returning anything

    And checked config and the propertie is there (<data alias="ShowInFooter">1</data>)

    @Seb - Thanks again, but still not returning anything?  Wondering if its my select statement thats wrong?

  • Lee 1130 posts 3088 karma points
    Jul 16, 2009 @ 17:47
    Lee
    1

    HA HAAAAAAAA

    I did it, I did it, I did it... Yes I'm quite pleased with myself - I was right, changed my select slighty and now it works

    <xsl:for-each select="$currentPage/ancestor-or-self::node/descendant-or-self::node">

    Really appreciate everyones help, many thanks

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jul 17, 2009 @ 09:45
    Warren Buckley
    0

    Glad you got there in the end Lee.

    XSLT & XPath does have a learning curve but I think it is worth sticking to, at least until 4.1 when you can use Aaron's Linq2Umbraco instead.

Please Sign in or register to post replies

Write your reply to:

Draft