Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1470 posts 3427 karma points c-trib
    Sep 16, 2009 @ 12:05
    Simon Dingley
    0

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

    My XSLT is by no means great and I am struggling with this one so would appreciate some pointers please if anyone can assist:

    I have the following snippet of XSLT:

        <xsl:variable name="SelectedStartNode" select="/macro/StartNode" />
    
        <xsl:variable name="NewsItems">
            <xsl:choose>
                <xsl:when test="$SelectedStartNode = ''">
                    <xsl:value-of select="$currentPage/ancestor::root/node  /descendant::node [@nodeTypeAlias = 'News']" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="umbraco.library:GetXmlNodeById($SelectedStartNode) /descendant::node [@nodeTypeAlias = 'News']"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

    That seems to be throwing the following exception:

    System.Xml.Xsl.XslTransformException: To use a result tree fragment in a path 
    expression, first convert it to a node-set using the msxsl:node-set() function. 
  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Sep 16, 2009 @ 12:41
    Sebastiaan Janssen
    0

    I don't think you can create a variable variable (so to speak). What I've done in the past is create two variables and pass them as an xsl param to an xsl template. So in the call-template, I do an xsl choose to determine which of the two variables I should pass.

    Would love to know if there's a better solution!

  • Tommy Poulsen 514 posts 708 karma points
    Sep 16, 2009 @ 13:16
    Tommy Poulsen
    0

    The problem is probably that your NewsItems variable content is not interpreted as xml. Possible the solution would be to replace variable value-of by copy-of.

    You could check out this thread also.

    >Tommy

     

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Sep 16, 2009 @ 13:47
    Simon Dingley
    0

    Sebastiaan, I don't believe you can change the value of a variable after it has been set but what I am doing is trying determine what value to set.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Sep 16, 2009 @ 13:48
    Simon Dingley
    0

    Unfortunately no joy with your solution either Tommy

  • Tommy Poulsen 514 posts 708 karma points
    Sep 16, 2009 @ 20:15
    Tommy Poulsen
    1

    Simon, I just tried your initial code, and it seems to work without errors on my side - just with a

    <xsl:value-of select="$NewsItems"/>

    added.

    Hope you work it out.

    >Tommy

     

     

  • mummmybot 3 posts 23 karma points
    Apr 19, 2010 @ 19:49
    mummmybot
    0

    I am getting this too, and pulling my hair out!

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Apr 19, 2010 @ 20:30
    Peter Duncanson
    0

    I can't recreate this one and looking at it, it looks like it "should" work as all you are doing is treating your first variable as a string.

    Might be worth coercing it to a string using string():

    <xsl:variable name="SelectedStartNode" select="string(/macro/StartNode)" />

     

     

     

  • webangelo 107 posts 190 karma points
    Apr 19, 2010 @ 22:03
    webangelo
    4

    BTW, the error it throws is slightly off.  It is actually telling you to use the msxml:node-set() function. If you are trying to cycle through the NewsItems later you may need to do this to tell the XML it is working with a node-set:

    <xsl:for-each select="msxml:node-set($NewsItems)/node">
  • Vincent 75 posts 98 karma points
    Jul 21, 2010 @ 21:10
    Vincent
    0

    How did you solve this? I'm getting the same error...

    Thx!

     

    Edited : 

    Got this working, thanks to webangelo !

  • Ankur Patel 2 posts 38 karma points
    Aug 27, 2010 @ 13:39
    Ankur Patel
    0

    Hi there,

    I have tried  the that code

     select="msxml:node-set($NewsItems)/node">

    It is fixing Error while saving time but its is not retrivin my node-set....

    is any one can help me please.......

  • mfeola 117 posts 221 karma points
    Nov 04, 2010 @ 16:47
    mfeola
    0

    I am having the same issue.  I want to get the root node of a content tree at level 1 but if the current page is at level 1 i want to get that.  here is my code:

    <xsl:variable name="rootPageID">
      <xsl:choose>
        <xsl:when test="$currentPage/@level = 1">
          <xsl:value-of select="$currentPage"/>
        <xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$currentPage/ancestor::* [@level = 1]"/>
        <xsl:otherwise>
      <xsl:choose>
    <xsl:variable name="rootPage" select="msxml:node-set($rootPageID)"/>

    now i get no error but i get no content either

  • mfeola 117 posts 221 karma points
    Nov 05, 2010 @ 16:37
    mfeola
    1

    well, i found a way around it.  i created a template that gets called in the choose item instead of setting a value:

      <xsl:variable name="rootNode" select="$currentPage/ancestor::* [@level = 1]"/>
      <xsl:choose>
        <xsl:when test="$currentPage/@level = 1">
          <xsl:call-template name="getTopNavigation">
            <xsl:with-param name="rootPage" select="$currentPage"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="getTopNavigation">
            <xsl:with-param name="rootPage" select="$rootNode"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
  • David Conlisk 432 posts 1008 karma points
    Nov 17, 2011 @ 10:49
    David Conlisk
    4

    I was tearing my hair out with this one too, but here's a solution that works (thanks to Lee Kelleher): 

    <xsl:variable name="nodes">
        <xsl:choose>
            <xsl:when test="$collegeId != -1">
                <!-- Grab all news items that have been tagged with this school/college -->
                <root>
                    <xsl:copy-of select="$currentPage/ancestor::Homepage[@isDoc]/NewsContainer[@isDoc]/DateFolder[@isDoc]/DateFolder[@isDoc]/NewsItem[@isDoc and ./schoolsColleges/XPathCheckBoxList/nodeId = $collegeId]"/>
                </root>
    
            </xsl:when>
            <xsl:otherwise>
                <!-- Grab all news items that have been flagged to display on home page -->
                <root>
    
                    <xsl:copy-of select="$currentPage/ancestor::Homepage[@isDoc]/NewsContainer[@isDoc]/DateFolder[@isDoc]/DateFolder[@isDoc]/NewsItem[@isDoc and appearsOnHomepage = 1]"/>
                </root>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    
    <xsl:variable name="matchedNodes" select="msxml:node-set($nodes)/root/*"/>

     Things to note:

    within the choose branches, I'm wrapping the results of <xsl:copy-of> (not value-of) with a <root></root> node. This means that my result will have a single root node, e.g. <root><item1/><item2/></root> instead of <item1/><item2/>.

    I'm calling msxml:node-set to convert my result to a proper node set. This works now because there is a single root element in $nodes (that I added).

    I'm using msxml:node-set($nodes)/root/* to return all nodes below my root node into $matchedNodes.

    Hope that helps someone!

    David

  • ZuB 3 posts 23 karma points
    Mar 21, 2012 @ 12:34
    ZuB
    0

    @David

    It does :-)

     

  • Giorgos Grispos 145 posts 179 karma points
    Nov 07, 2012 @ 18:16
    Giorgos Grispos
    0

    @David you saved my night!

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Nov 11, 2014 @ 10:08
    Simon Dingley
    0

    I've just had to return to a v4.7.1 site do an update and after a long time away from XSLT I hit this issue again. The funny thing it I keep finding my own threads when searching for these historic issues but thankfully @David provided me with the answer again! :) I owe you a beer at the UK Festival this year if you're attending?

  • David Conlisk 432 posts 1008 karma points
    Nov 11, 2014 @ 11:11
    David Conlisk
    0

    Haha, glad you're still getting value from that post @Simon, I know that I came back to it again and again with XSLT sites. Yes I'll be at the UK Fest - see you there :)

Please Sign in or register to post replies

Write your reply to:

Draft