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
    Mar 15, 2011 @ 10:32
    Tony Kiernan
    0

    "first convert it to a node-set using the msxsl:node-set()"

    I am trying to conditionally set the select in a for-each loop using the following (counter simply counts if hte current page has any 'links' below it):

    <xsl:variable name="selecter">
        <xsl:choose>
          <xsl:when test="$counter = 0">
            <xsl:value-of select="$currentPage/ancestor-or-self::Site//Link" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentPage/Link"/>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:variable>

    <xsl:for-each select="$selecter">
    ....
    </xsl:for-each>

    If I test this in the Umbraco admin area it throws up this error

    To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set()

    If I simply put each select statement directly into the variable they both work.  It's the select that breaks it. 

    All suggestions gratefully welcomed.  Or, call me an idiot and point me to the relevant documentation

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 15, 2011 @ 13:04
    Jan Skovgaard
    0

    Hi Tony

    I'm guessing you should use msxsl:node-set() around $selecter in your for-each like this: msxsl:node-set($selecter)...does this work?

    Otherwise I would like to see a snippet of the XML that gets returned to you using a copy-of on the variable.

    (Remember to add the correct namespace for the msxsl stuff!)

    /Jan

  • Tony Kiernan 278 posts 341 karma points
    Mar 15, 2011 @ 15:16
    Tony Kiernan
    0

    What would bew the correct namespace for that?  Everything else I can find suggests

    msxml:node-set($selecter)

    Which I would guess uses

    xmlns:msxml="urn:schemas-microsoft-com:xslt"

    Do you mean something different?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 15, 2011 @ 15:47
    Jan Skovgaard
    0

    Hi Tony

    Yes, that's what I mean. Can't remember the difference (if any) between those two...

    But otherwise the namespace for what I mentioned is fairly easy to add, since it's almost identical to the one you posted. It looks like...

    xmlns:msxls="urn:schemas-microsoft-com:xslt"

    However...more importantly did you get it to work or is it still bugging?

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 15, 2011 @ 16:49
    Chriztian Steinmeier
    2

    Hi Tony,

    You need to use copy-of instead of value-of in your selecter variable - and then use msxml:node-set($selecter) in the for-each statement:

    <xsl:variable name="selecter">
        <xsl:choose>
            <xsl:when test="$counter = 0">
                <xsl:copy-of select="$currentPage/ancestor-or-self::Site//Link" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="$currentPage/Link" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    
    <xsl:for-each select="msxml:node-set($selecter)">
        <!-- do stuff -->
    </xsl:for-each>
    

    Please note: Since the nodes you are processing are now copies, you won't be able to access elements/attributes on parent elements etc. 

    /Chriztian 

  • Tony Kiernan 278 posts 341 karma points
    Mar 15, 2011 @ 20:21
    Tony Kiernan
    0

    Fantastic!  Thank you 

    Got my list working now.  But, with none of the actual values displaying.  I'm guessing this was what you meant by your 'please note'.  How can I get round this?  Or can I?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 15, 2011 @ 20:53
    Tom Fulton
    0

    I think Chriztian just meant you won't have access to nodes above the ones you are selecting in your variable.  Does your for-each need them?

    Also - one thing I always seem to have to do when using msxml:node-set is add a /* - for some reason it seems to add an extra element?  Try this and see if it works

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

    And if it does maybe Chriztian can explain :)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 15, 2011 @ 21:54
    Chriztian Steinmeier
    1

    Hi Tony (+ Tom),

    Tom's right about the "extra" element - this particular for-each will actually only run once, for a virtual wrapper element holding the copied links - usually I have a template for the copied elements and then I do <xsl:apply-templates select="msxml:node-set($variable)" /> instead, and due to some built-in magic my template will be instantiated for every element.

    "Now back to you..." :-)

    If you just need to do something simple for every link, or if you need to use the (new) position() value for each element, put the code inside the for-each like this, but be specific about the elements (you copied Link elements, so ask for them):

    <xsl:for-each select="msxml:node-set($selector)/Link">
        <!-- Assuming elements like this: <Link>1057</Link> -->
        <a href="umbraco.library:NiceUrl(.)">
            <xsl:value-of select="concat('#', position())" />
        </a>
    </xsl:for-each>
    

    But if you're doing something wee more elaborate, try the template approach:

    <xsl:template match="/">
        <dl>
            <xsl:apply-templates select="msxml:node-set($selector)/Link" />
        </dl>
    </xsl:template>
    
    <xsl:template match="Link">
        <!-- Assuming elements like this: <Link url="http://lego.com/LOST" priority="highest">LEGO LOST: The Pilot (I wish...)</Link> -->
        <dt><xsl:value-of select="." /></dt>
        <dd class="{@priority}">
            <a href="{@url}">
                <xsl:value-of select="substring-after(@url, 'http://')" />
            </a>
        </dd>
    </xsl:template>

    In either case - have fun :-)

    /Chriztian

     

  • Tony Kiernan 278 posts 341 karma points
    Mar 15, 2011 @ 22:37
    Tony Kiernan
    0

    That's more than sorted me out.  Thank you all very much.

  • pooja 15 posts 35 karma points
    Sep 21, 2011 @ 11:05
    pooja
    0

    hi this was help full to me also.

    but i am getting some error . I am getting data from 3 list in single dataview. and when i set variable as mentioned above for first list  the other two list are not showing data. if i set the variable as mentioned for 2nd list the 3rd list not showing data can you please help me.

     

Please Sign in or register to post replies

Write your reply to:

Draft