Copied to clipboard

Flag this post as spam?

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


  • George 28 posts 71 karma points
    Apr 07, 2011 @ 09:04
    George
    0

    "Expression must evaluate to a node-set"

    Hey all - this question seems fairly similar to the question at XSLT nodeset question, but that one's a year old and doesn't really answer my question.

    I'm trying to pass a set of nodes (actually just one in this case) from one template to another template, using xsl:call-template. But I keep getting "expression must evaluate to a node-set". I'm using msxsl:node-set() to try and convert my "select" into a node set. In this case I could just pass through an id and use that to reinstantiate the (single) node on the other side, but I'd like to know how to do this since there are other cases in my code where I want to pass through more than one node. Any help would be greatly appreciated. :)

    SideNavigation.xslt:

    <?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:msxsl="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 msxsl umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

        <xsl:include href="SideNavigation_PrintChildren.xslt"/>

        <xsl:output method="xml" omit-xml-declaration="yes" />

        <xsl:param name="currentPage"/>

        <xsl:variable name="sectionTopNode" select="$currentPage/ancestor-or-self::* [@level=2]" />
       
        <xsl:template match="/">

            <xsl:call-template name="SideNavigation_PrintChildren">
                <xsl:with-param name="printChildrenOf" select="msxsl:node-set($sectionTopNode)" />
            </xsl:call-template>

           
        </xsl:template>

    </xsl:stylesheet>

    SideNavigation_PrintChildren.xslt:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="msxsl">
        <xsl:output method="xml" indent="yes"/>
        <xsl:param name="printChildrenOf" />
            <xsl:template name="SideNavigation_PrintChildren">
            <ul>
                <xsl:variable name="children" select="$printChildrenOf/* [@isDoc]" />
            </ul>
       </xsl:template>
    </xsl:stylesheet>

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 07, 2011 @ 09:53
    Chriztian Steinmeier
    0

    Hi George,

    When you assign a variable using the select attribute, you don't need to use the node-set() function - it's a perfectly valid node-set already.

    In your "SideNavigation_PrintChildren.xslt" file, move the <xsl:param name="printChildrenOf" /> declaration inside of the named template (i.e., 2 lines down) and it should start working.

    /Chriztian 

  • George 28 posts 71 karma points
    Apr 07, 2011 @ 10:22
    George
    0

    Thanks heaps Chriztian, that worked a treat. I did some reading on xsl:param, and apparenlty this changes the param from being global to being local. Do parameters to templates I call always have to be local? I'm assuming that global parameters are things that are passed to the "top level" template, and things that that template passes to it's children should be declared as local?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 07, 2011 @ 12:46
    Chriztian Steinmeier
    1

    Hi George,

    When you do a call-template using with-param, the parameter you reference should be a local param defined in the template you call - but you can pass the value of any global or local variable on to the template. The template itself can also access any globally defined variables/parameters in the stylesheet.

    Global parameters have one special feature - they can be set from "The Outside" (i.e., .NET or whichever technology is using the XSLT Processor) - this is how Umbraco passes the $currentPage context into macros.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft