Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Jun 06, 2010 @ 23:08
    Nigel Wilson
    0

    Use a variable within a variable

    I am missing something obvious, so would appreciate someone highlighting the error of my ways:

    Within a template I am setting a parameter as follows:

    <xsl:param name="fieldToSearch"/>

    Then I am attempting to use the value as follows:

    <xsl:variable name="evenYetPossibleNodes" select="$nodeSetOne [contains(data [@alias=$fieldToSearch], $searchTerm)]" />

    This doesn't work however if I hard code the value as follows it works fine.

    <xsl:variable name="evenYetPossibleNodes" select="$nodeSetOne 
    [contains(data [@alias='BannerGroups'], $searchTerm)]" />

    Any suggestions ?

    Thanks

    Nigel

  • Paul Blair 466 posts 731 karma points
    Jun 07, 2010 @ 00:01
    Paul Blair
    0

    Hvae tried outputing your variable to make sure it actually has the value BannerGroups i.e.

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

    If that works then try

    <xsl:value-of select="data [@alias=$fieldToSearch]" />

    Working on a holiday? Must be raining there too :)

     

  • Nigel Wilson 945 posts 2077 karma points
    Jun 07, 2010 @ 00:43
    Nigel Wilson
    0

    Hey Paul

    Yep sad but true - I am also guilty of not being able to let go of a work related challenege at the weekends . . .

    I have been challenged with changing the XSLT search module to provide for multiple inputs (free text and checkboxes).

    Thankfully I have nailed it and now applying some finishing touches.

    Your suggestion unfortunately didn't solve the problem as the template didn't output anything (even static text), but your suggestion did make me go back and look at how I was passing the value into the template

    Previously I had this

    <xsl:with-param name="fieldToSearch" select="BannerGroups"/>

    Now I have this and it appears to be working fine

    <xsl:with-param name="fieldToSearch">BannerGroups</xsl:with-param>

    So thanks from a fellow kiwi - stay warm and dry !

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 07, 2010 @ 01:26
    Lee Kelleher
    0

    Hi Nigel, just to throw my 2-pence worth in.

    When you first tried to pass the value in the 'with-param'...

    <xsl:with-param name="fieldToSearch" select="BannerGroups"/>

    ... because it was in the 'select' attribute, the param is trying to resolve a node-set (or XPath expression).  It doesn't know that it should treat the value as a text/string.

    In your second attempt...

    <xsl:with-param name="fieldToSearch">BannerGroups</xsl:with-param>

    The value is evaluated as a text/string - rather than a node-set or XPath expression.

    If you really wanted to use the 'select' attribute, you could do the following...

    <xsl:with-param name="fieldToSearch" select="string('BannerGroups')"/>

    ... but since you already got it working, no worries.

    Cheers, Lee.

  • Nigel Wilson 945 posts 2077 karma points
    Jun 07, 2010 @ 01:30
    Nigel Wilson
    0

    Hi Lee

    Thanks for that - slowly but surely I'll get my head around the nuances of Umbraco & XSLT.

    It's lots of fun and causes lots of head scratching !

    Cheers

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft