Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    May 06, 2011 @ 21:53
    FarmFreshCode
    0

    List subpages of specific DocType - XSLT

    Im having trouble listing out the subpages of this specific node (Quotes & Testimonials). I want to embed this list into my master template using a maco. Below is a screenshot of my File Tree. You can see that I have 4 child pages that I am wanting to show listed.

    You can see my current XSLT code below.. The alias for the doctype that I am trying to target is "QuotesTestimonials" however I guess I wouldn't mind setting it to the specific node id 1789 either

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

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="documentTypeAlias" select="string('QuotesTestimonials')"/>

    <xsl:template match="/">

    <ul>
    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • Rich Green 2246 posts 4008 karma points
    May 06, 2011 @ 22:11
    Rich Green
    2

    You can use GetXmlNodeById

     <xsl:for-each select="umbraco.library:GetXmlNodeById(1789)/QuotesTestimonials">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    

    Rich

  • FarmFreshCode 225 posts 422 karma points
    May 06, 2011 @ 22:24
    FarmFreshCode
    0

    @Rich - Thanks! I had to change it a little but that was a better way to go about it.

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1789)/NewQuote">

    In your example "1789" was the same thing as "QuotesTestimonials" so I needed to list the docType of the child pages which was "NewQuote" and now we are all set. Thanks. Im sure I'll be using this a lot.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 06, 2011 @ 22:36
    Jan Skovgaard
    0

    HI FFC

    The approach by Rich is working for you and that is of course great.

    But I believe that it should also be possible to achieve using an apply-template so there is no need to use the GetXmlNodeById extension and no need for the for-each loop as well.

    You should be able to do something like this...

    <ul>
      <xsl:apply-templates select="$currentPage/ListsAlias/QuotesTestimonials/*[@isDoc]" />
      </ul>
    </xsl:template>

    <xsl:template match="TheAliasOfTheBelowTheQuotesBranch">
       <li>
             <a href="{umbraco.library:NiceUrl(@id)}">
                 <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:template>

    Just an alternative suggestion :-)

    /Jan

  • Rich Green 2246 posts 4008 karma points
    May 06, 2011 @ 22:40
    Rich Green
    1

    Hey Jan,

    I'm not sure that's going to work using the currentPage?

    Rich

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 06, 2011 @ 23:04
    Jan Skovgaard
    1

    Hi Rich

    depends where the macro is placed...doesn't it? :-) (Maybe I misunderstand but the notion I got from the initial post was that this was intended to be placed on the frontpage of the site - then it should work).

    But to make sure this will work independent of where the macro is placed it's of course better to use the root node as the starting point.

    Then the sample should look like this

    <xsl:variable name="root" select="$currentPage/ancestor-or-self::* [@isDoc][@level=1]" />

    <ul>
      <xsl:apply-templates select="$root/ListsAlias/QuotesTestimonials/*[@isDoc]" />
      </ul>
    </xsl:template>

    <xsl:template match="TheAliasOfTheBelowTheQuotesBranch">
       <li>
             <a href="{umbraco.library:NiceUrl(@id)}">
                 <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:template>

    /Jan

  • Rich Green 2246 posts 4008 karma points
    May 07, 2011 @ 08:31
    Rich Green
    0

    Hey Jan,

    I assumed FFC needed it to work from all pages, either way your last solution is much nicer as it doesn't rely on hardcoding the node id :) (though it does rely on the structure staying the same)

    Rich 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2011 @ 11:22
    Jan Skovgaard
    0

    Hi Rich

    Yes you have a very good point with that and I tried playing around with it since I'm pretty sure it should be possible to simply just match the DocumentType/Element in the XSLT so it's independent of the structure...but when I was trying I made my browser crash...so probably did something wrong :D

    But I will keep trying and post it in here as soon as I figure out how to.

    Cheers.

    /Jan

  • Max 144 posts 166 karma points
    Sep 21, 2011 @ 13:07
    Max
    0

    How do i make  a list of other document types except 1  any xslt code examples wil be very useful

     

Please Sign in or register to post replies

Write your reply to:

Draft