Copied to clipboard

Flag this post as spam?

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


  • Tony Kiernan 278 posts 341 karma points
    Nov 09, 2010 @ 18:37
    Tony Kiernan
    0

    Newbie: Getting all pages with a certain property

    I've taken over a project from someone else, and this is my first time using umbraco.  I have had to rearange the nodes in this site.  As a result, top level node 'Catalogue' is now under top level 'Site'.  I want all pages in the site with a certain checkbox ticked to include them in a slider on the home page.

    Currently the xslt is getting:

    <xsl:for-each select = "umbraco.library:GetXmlAll()/Page[@nodeName='Catalogue']/CatalogueItem[showInSlider=1]">

    How do I amend this to take into account the change in structure?

  • Tony Kiernan 278 posts 341 karma points
    Nov 11, 2010 @ 11:56
    Tony Kiernan
    0

    I should point out I've inherited a project and suspect a lot of stuff is not done 'correctly'

    OK, I've got rid of the named nodes.

    <xsl:for-each select = "$currentpage/* [@isDoc and showInSlider=1]">

    This works for everything below the current page (obviously).  I want to break out of that and pull all pages where showInSlider is checked.  Something like:

    <xsl:for-each select = "umbraco.library:GetXmlAll()/* [@isDoc and showInSlider=1]">

    Any help will be gratefully received.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Nov 11, 2010 @ 12:01
    Warren Buckley
    0

    Hi Tony.
    Obviously you are along the right lines with the currentPage only getting the child items.
    You need to ammend your XSLT so it first walks upto the top level node from the currentPage first then to apply your child filter you need.

    So for example:

    <xsl:for-each select = "$currentpage/ancestor-or-self::myHomeNodeAlias/* [@isDoc and showInSlider=1]">

    Hope this helps.

    Warren :)

     

  • Tony Kiernan 278 posts 341 karma points
    Nov 11, 2010 @ 12:15
    Tony Kiernan
    0

    Thanks for that.  However, pasting your response results in this error

    The variable or parameter 'currentpage' is either not defined or it is out of scope

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage" />

    <xsl:template match="/">
              
        <ul>
          <xsl:for-each select = "$currentpage/ancestor-or-self::myHomeNodeAlias/* [@isDoc and showInSlider=1]">
            <li>
              <xsl:value-of select="@nodeName" />
            </li>
          </xsl:for-each>
          <li>
            Hardcoded
          </li>
        </ul>
              

    </xsl:template>

    </xsl:stylesheet>

    Should I be replacing 'myHomeNodeAlias'?

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Nov 11, 2010 @ 12:21
    Warren Buckley
    0

    Sorry a typo on my behalf. $currentpage should be $currentPage and yes obviously the nodetype alias should be changed from myHomeNodeAlias to the alias of the top level node. Normally people have a specific document type for the homepage. If this is not the case let me know and we can try another xpath.

    But basically your goal is to get from currentPage to walk up the tree to the most top level node and then to walk back down it with your
    /* [@isDoc and showInSlider=1]

    Warren

  • Tony Kiernan 278 posts 341 karma points
    Nov 11, 2010 @ 12:32
    Tony Kiernan
    0
    <xsl:for-each select = "$currentPage/ancestor-or-self::site/* [showInSlider=1]">

    Returning nothing

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Nov 11, 2010 @ 12:50
    Warren Buckley
    0

    OK sorry my bad again as I am juggling a few things here.

    As this is saying only select one level of XML child nodes beneath the <site> node which in this case are property nodes of the site node.
    So to say fidn this no matter how many levels deep we need to use //. However be warned this is quite an expensive xpath call and would be better to be more speicifc in your xPath.

    <xsl:for-each select = "$currentPage/ancestor-or-self::site//* [showInSlider=1]">
  • Tony Kiernan 278 posts 341 karma points
    Nov 11, 2010 @ 13:01
    Tony Kiernan
    0

    Thank you so very much.  This should help me with just about everything I've been having issues with.

Please Sign in or register to post replies

Write your reply to:

Draft