Copied to clipboard

Flag this post as spam?

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


  • Hamish 96 posts 154 karma points
    Mar 25, 2010 @ 06:32
    Hamish
    0

    Why does value-of not work when inside a param or variable

    When I use:

    <xsl:variable name="list" select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"/>

    It works fine... but when I try to do the following:

    <xsl:variable name="list">
         <xsl:choose>
            <xsl:when test="$currentPage/@nodeTypeAlias = 'Resource Listing'">
                <xsl:value-of select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"/>
            </xsl:otherwise>
         </xsl:choose>
    </xsl:variable>

    It breaks the xslt???

    Does any have any insights to this?

     

     

     

  • skiltz 501 posts 701 karma points
    Mar 25, 2010 @ 07:40
    skiltz
    0

    Where is $currentPage declared? Maybe its gone out of scope??

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 25, 2010 @ 08:35
    Jan Skovgaard
    0

    What kind of error message do you receive when trying to save the XSLT?

    And have you tried to see if the XSLT in fact works if you check the "Skip error testing" box?

    /Jan

  • Josh Reid 182 posts 258 karma points
    Mar 25, 2010 @ 08:44
    Josh Reid
    1

    Hamish if you are finding that you get the error:

    'cannot convert result tree fragment to nodeset'

    Then try doing this with your variable when you need to use the list variable as for-each, etc:

    <xsl:for-each select="msxml:node-set($list)/node">

    While the nodeset remains intact and as a nodeset when you use inside the variable select, it becomes a result tree fragment when declared by value-of.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 25, 2010 @ 09:00
    Chriztian Steinmeier
    3

    Hi Hamish,

    Whenever you use value-of, the processor evaluates the result as a string, whereas select returns a nodeset. If you need to conditionally select the node(s) for a variable, you need to use copy-of instead of value-of, but then you're actually getting a "result tree frament" (as Josh mentions) - you can convert that to a nodeset using the msxml:node-set() function (remember to declare the msxml prefix - the standard XSLT templates does that automatically). So domething like this:

     

    <xsl:variable name="list">
         
    <xsl:choose>
           
    <xsl:when test="$currentPage/@nodeTypeAlias = 'Resource Listing'">
               
    <xsl:copy-of select="$currentPage/node[not(data[@alias = 'umbracoNaviHide'] = 1)]"/>
           
    </xsl:when>
           
    <xsl:otherwise>
               
    <xsl:copy-of select="...something else..."/>
            </xsl:otherwise>
         
    </xsl:choose> </xsl:variable> ... <!-- Use like this: --> <xsl:for-each select="msxml:node-set($list)/node">

     

    /Chriztian

  • Josh Reid 182 posts 258 karma points
    Mar 25, 2010 @ 09:30
    Josh Reid
    0

    Well put Chriztian, I was probably a tad brief before...

    Mental note to write up more fully in the future ;)

  • Hamish 96 posts 154 karma points
    Mar 25, 2010 @ 22:08
    Hamish
    0

    Thanks guys for your help and the insight of how value-of actually works..

    That info helped save my sanity...

     

Please Sign in or register to post replies

Write your reply to:

Draft