Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Oct 23, 2011 @ 16:39
    Stefan
    0

    Selection of property on all pages

    Hi.

    I have a sidebar on my site, and I'm struggling with getting the contents to show on all pages.

    This will show the submitted url for a link. It works on all pages regarding of $currentPage.

    <xsl:value-of select="$currentPage/ancestor::root//Homepage/SidebarLinks/SidebarLinksItem/sidebarLinkUrl" />

    The problem is that I can't get it to work with a for-each statement (to select every link and populate them in a unordered list.

    <xsl:variable name="Links" select="$currentPage/ancestor::root//Homepage/SidebarLinks/SidebarLinksItem/" />
    <xsl:for-each select="$Links">

    That would produce an error like this:
    System.Xml.Xsl.XslLoadException: Unexpected token '' in the expression.

    Maybe I'm not getting the syntax right in the selection?

    Thanks in advance!

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 23, 2011 @ 16:49
    Jan Skovgaard
    0

    Hi Stefan

    I think there might is a syntax error elsewhere in your code where you have forgotten to add " somewhere.

    Could you post all of the code perhaps?

    I also suspect you could write the code in a more efficient manner, but let's see what you got right now first :)

    /Jan

  • Stefan 117 posts 215 karma points
    Oct 23, 2011 @ 17:56
    Stefan
    0

    Here's the code:

    <div class="sidebar-container">
    <p class="sidebar-header shadow-light">Links</p>

    <ul class="links">

    <xsl:variable name="Links" select="$currentPage/ancestor::root//Homepage/SidebarLinks/SidebarLinksItem/" />
    <xsl:for-each select="$Links">

    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(sidebarLinkUrl)" />
    </xsl:attribute>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>

    </xsl:for-each>

    </ul>
    </div>

    From what I've found, It's just the variable "Links" that won't play nice :P

    But again, I'm not sure if it's the correct syntax used in select="", even though it's working just fine in other contexts.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 23, 2011 @ 18:44
    Jan Skovgaard
    0

    Hi Stefan

    Try removing the last "/" in your variable. That part should not be neccesary.

    /Jan

  • Stefan 117 posts 215 karma points
    Oct 23, 2011 @ 23:36
    Stefan
    0

    When I remove the trailing "/" from my variable, I get an error saying:

    Error occuredSystem.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    .....

    When I remove the variable I don't get any errors. I just don't understand why I can get the correct values (without errors) when using the value-of select, and not in a for-each loop?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 24, 2011 @ 00:27
    Dennis Aaen
    0

    Hi Stefan,

    I think you have to make a check on the property, To make sure that is not empty. http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    <div class="sidebar-container">
     
    <p class="sidebar-header shadow-light">Links</p>

     
    <ul class="links">

       
    <xsl:variable name="Links"select="$currentPage/ancestor::root//Homepage/SidebarLinks/SidebarLinksItem"/>
       
    <xsl:iftest="$Links!=''">
     <xsl:for-each select="$Links">
         
           
    <li>
             
    <a>
               
    <xsl:attribute name="href">
                 
    <xsl:value-of select="umbraco.library:NiceUrl(sidebarLinkUrl)"/>
               
    </xsl:attribute>
               
    <xsl:value-of select="@nodeName"/>
             
    </a>
           
    </li>
         
       
    </xsl:for-each>    
       
    </xsl:if>
     
    </ul>
    </div>
    Hope something like this will help you to solve your question.

    /Dennis

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 24, 2011 @ 08:18
    Jan Skovgaard
    0

    Hi Stefan

    As Dennis mentions you can make a check to see if $Links has a value (it does not have a value, when you save the XSLT file and that's why you get the new error). You can also ignore this error by simply just checking the "skip errors" checkbox.

    Then your XSLT file should be working just fine.

    /Jan

  • praveity 100 posts 125 karma points
    Oct 25, 2011 @ 12:06
    praveity
    0

    the <xsl:for-each/> requires the nodelist for iterationg.. 

    you should tell it to be get the list of nodes. some what like this in your case

    <xsl:variablename="Links"select="$currentPage/ancestor::root//Homepage/SidebarLinks/SidebarLinksItem/*[@isDoc]"/>

    This will loop through all the child doctype of SidebarLinksItem.

Please Sign in or register to post replies

Write your reply to:

Draft