Copied to clipboard

Flag this post as spam?

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


  • Steve D 11 posts 41 karma points
    Feb 01, 2010 @ 10:42
    Steve D
    0

    variable template parameter problem

    I am calling a template with the following code:

    <xsl:template match="/">
      <xsl:variable name="level" select="$currentPage/macro/startLevel"/>
      <xsl:variable name="showList" select="$currentPage/macro/showList"/>

      <ul class="{$showList}">

      <xsl:call-template name="drawNodes">
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level ='1']" />
      </xsl:call-template>

      </ul>
    </xsl:template>

    which validates correctly, however when I use the "level" variable in the parent select value I get an error:

    <xsl:template match="/">
      <xsl:variable name="level" select="$currentPage/macro/startLevel"/>
      <xsl:variable name="showList" select="$currentPage/macro/showList"/>

      <ul class="{$showList}">

      <xsl:call-template name="drawNodes">
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level = $level]" />
      </xsl:call-template>

      </ul>
    </xsl:template>

    error:

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent)
    at

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)

    I think it may be to do with evaluating to a list, but I have no idea why replacing a static '1' with the variable $level (which will contain a '1') causes an error?

     

    Any help would be gratefully received.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 01, 2010 @ 10:48
    Sebastiaan Janssen
    0

    The level might be null or empty, the XSLT parser probably can't validate the xslt without knowing this, try this:

    <xsl:if test="string($level) != ''>
     <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level = $level]" />
    </xsl:if>
Please Sign in or register to post replies

Write your reply to:

Draft