Copied to clipboard

Flag this post as spam?

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


  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 12:05
    Probocop
    0

    Listing subpages of a specific node?

    On my homepage I need to list the latest two news articles. How would I go about listing the subpages of a specific node (news page)?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 15, 2010 @ 12:10
    Ismail Mayat
    0

    Probocop,

    See here http://our.umbraco.org/forum/using/ui-questions/10708-Path-to-Name-not-DocumentType in the drop down select template that lists specific type. I also recommend downloading and installing cws package and that is a great starter kit with plenty of good basic examples.

    Regards

    Ismail

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 12:28
    Warren Buckley
    0

    Hello Probocop,
    Whithout knowing your node structure it is hard to say what XSLT you will need.

    But I can try and do something for you here
    (it assumes that your news folder document type is beneath the home node, and that the news folder contains the items you want to list)

    <xsl:variable name="newsFolderNode" select="$currentPage/newsFolderDocTypeAlias" />
    <xsl:for-each select="$newsFolderNode/newsItemDocTypeAlias">
      <xsl:sort select="@createDate" order="descending"/>

      <xsl:if test="position() &lt;=2">
        <xsl:value-of-select="current()/@nodeName" /><br/>
      </xsl:if>
    </xsl:for-each>

    I hope this is of some use to you. If not please post a screenshot of your tree, showing what page you are on and what data you want to retrieve as without knowing your content tree it's hard to help out.

    Warren :)

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 13:33
    Probocop
    0

    Hi Warren,

    Thanks for the reply.  Yes I believe I am after something very similar to what you posted, I've attached a screengrab of my content tree.  The page I'm on is the 'Home Page', and I'm trying to grab the nodes created under the 'News' page.

    Thank you very much for your help! 

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 13:45
    Warren Buckley
    0

    What version of Umbraco are you using?
    If it is 4.5 and are using the new XML schema then my XSLT will work but obviously updating the documentTypeAliases as needed.

    Warren

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 13:46
    Probocop
    0

    I am running umbraco v 4.0.3 :)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 13:52
    Warren Buckley
    0

    OK so that is the old XML schmea so I can update the example for you

    <xsl:variable name="newsFolderNode" select="$currentPage/node [@nodeTypeAlias='newsFolderDocTypeAlias']" />
    <xsl:for-each select="$newsFolderNode/node [@nodeTypeAlias='newsItemDocTypeAlias']">
     
    <xsl:sort select="@createDate" order="descending"/>

     
    <xsl:if test="position() &lt;=2">
       
    <xsl:value-of-select="current()/@nodeName" /><br/>
     
    </xsl:if>
    </xsl:for-each>

     

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 13:59
    Probocop
    0

    Thanks for the example, I'm not managing to get it working though.  I assume I just change the 'newsItemDocTypeAlias' for the alias of the news article alias? (in my case it is 'News Article')

    It is giving me the following error:

    Error occured

    System.Xml.XmlException: The '=' character, hexadecimal value 0x3D, cannot be included in a name. Line 21, position 25. 
    at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
    at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 
    at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args) 
    at System.Xml.XmlTextReaderImpl.ParseElement() 
    at System.Xml.XmlTextReaderImpl.ParseElementContent() 
    at System.Xml.XmlTextReaderImpl.Read() 
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSiblingHelper() 
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling() 
    at System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChildAny() 
    at System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChild() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags) 
    at System.Xml.Xsl.Xslt.XsltLoader.XslIf() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags) 
    at System.Xml.Xsl.Xslt.XsltLoader.XslForEach() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags) 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadTemplate(NsDecl stylesheetNsList) 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)

    Any idea what's wrong?

    Thanks again for your help

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 14:09
    Warren Buckley
    0

    OK looking at your content tree.
    The "News" node what documet type is it and what is it's alias (found when you edit the document type, as it's not the name of the document type) ?

    Warren

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 14:30
    Warren Buckley
    0

    Also looking at your error seems there might be an = sign in the wrong place or that quotes are not round the nodetypeAlias

    Warren :)

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 14:34
    Thomas Höhler
    0

    It is that the <= in the position test was converted to &lt;=

    also the value of wasn't correct:

    try this

    <xsl:for-each select="$newsFolderNode/node [@nodeTypeAlias='newsItemDocTypeAlias']">
     
    <xsl:sort select="@createDate" order="descending"/>
     
    <xsl:if test="position() < 3">
       
    <xsl:value-of select="@nodeName" /><br/>
     
    </xsl:if>
    </xsl:for-each>

    hth, Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 14:40
    Thomas Höhler
    0

    The &lt;= is ok (was my fault) but the value-of wasn't correct anyway (also just a typo by Warren)

    Thomas

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 14:41
    Warren Buckley
    0

    Thomas, the value of that I suggested will work, its slightly longer but makes it easier to read for beginners to XSLT.
    i.e the current item in the loop's @nodeName value, however also your way will work and is shorthand once you are more comfortable with XSLT.

    Warren :)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 14:44
    Warren Buckley
    0

    Probocop if you are still having issues I recommend that you post your entire XSLT file on here, so that me or Thomas can take a look at it and try and help you out with your problem.

    Warren

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 14:45
    Thomas Höhler
    0

    Warren, you wrote

    <xsl:value-of-select=""...

    it should be:

    <xsl:value-of select=""...

    so, only a "-" too much but this won't work

    I only kicked the current() because of my editor, so you are right this might be better to understand for beginners

    Cheers, Thomas

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 15:03
    Warren Buckley
    0

    Cheers Thomas,
    I missed that typo.Like I said was typing it off the top of my head direct on the forum :)

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 15:18
    Probocop
    0

    Thank you both for all your help!

    It's not giving me any errors anymore, but it's also not returning anything.

    My XSLT file is as following:

    <?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="/">

    <xsl:variable name="newsFolderNode" select="$currentPage/node[@nodeTypeAlias='News Article']" />
    <xsl:for-each select="$newsFolderNode/node [@nodeTypeAlias='News Article']">
      <xsl:sort select="@createDate" order="descending"/>
      <xsl:if test="position() &lt; 3">
        <xsl:value-of select="@nodeName" /><br/>
      </xsl:if>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

    According to the alias field when editing the News Item doctype, it is 'News Article'

     

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 15:41
    Warren Buckley
    0

    Hello Probocop thanks for providing the XSLT, however I cannot see any problem with the XSLT at all.

    So let's check a couple of things (see images)

    Please make sure you are using the alias of the document type and not the name, also the document type alias is case sensitive.

    It is good practise to give each document type a different icon using the icon drop down when editting the document type, so you
    can see quicker and easily identify what nodes are when looking at the content tree.

    Warren :)

     

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 16:01
    Probocop
    0

    Hi Warren,

    I've actually managed to get it working finally.

    Sorry for the confusion on the alias too, the 'News' page has the alias of 'News Page' and the sub pages have the alias of 'newsArticle'

    I got it working with the following XSLT:

     

    <xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias='newsArticle'] ">
      <xsl:sort select="data [@alias = 'date']" order="descending"/>
      <xsl:if test="position() &lt; 3">
        <xsl:value-of select="@nodeName" /><br/>
      </xsl:if>
    </xsl:for-each>

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2010 @ 16:04
    Warren Buckley
    0

    Hello Probocop, the XSLT I wrote will work if you update the aliases correctly.

    However your way is still perfectly valid, it's just a longer version of the same thing I done, but as your starting out with XSLT it may be easier for you to read and understand.

    Don't forget to mark a reply as an answer to the solution, so that other people can easily find the solution.

    Warren :)

  • Probocop 51 posts 71 karma points
    Jul 15, 2010 @ 16:16
    Probocop
    0

    I've marked an answer, thank you very much for your help! 

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft