Copied to clipboard

Flag this post as spam?

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


  • Lee 1123 posts 3059 karma points
    Dec 21, 2009 @ 07:29
    Lee
    0

    Can I Do This? As In VS2010 Its Being Highlighted As Invalid Syntax?

    I want to be able to add a condition sort after a select depending on a Querystring value?  But if I put an <xsl:if> or <xsl:choose> after the select it gets highlighted as invalid with the 'red death worms' under my syntax??

    <xsl:for-each select="$searchResults"> 
        <xsl:choose>
            <xsl:when test="umbraco.library:Request('something') = 'something'">
                <xsl:sort select="./data [@alias = 'this']" data-type="number" />
            </xsl:when>
            <xsl:when test="umbraco.library:Request('something') = 'something'">
                <xsl:sort select="./data [@alias = 'that']" data-type="number" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:sort select="./data [@alias = 'another']" data-type="number" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 21, 2009 @ 07:31
    Sebastiaan Janssen
    0

    Yeah, it doesn't work because the sort has to be DIRECTLY after the for-each. The xsl:choose interferes with that. You should set some variables with the chosen sorting options first. I'll post an example in a minute.

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 21, 2009 @ 07:44
    Sebastiaan Janssen
    0

    Here's your code rewritten, something like this should work:

        <xsl:choose>
          <xsl:when test="umbraco.library:Request('something') = 'something'">
            <xsl:variable name="sortfield" select="./data [@alias = 'this']" />
          </xsl:when>
          <xsl:when test="umbraco.library:Request('something') = 'something'">
            <xsl:variable name="sortfield" select="./data [@alias = 'that']" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:variable name="sortfield" select="./data [@alias = 'another']" />
          </xsl:otherwise>
        </xsl:choose>
    
        <xsl:call-template name="example">
          <xsl:with-param name="item" select="."/>
          <xsl:with-param name="sortField" select="$sortField" />
        </xsl:call-template>
    

    Then, after the </xsl:template> item add a new template:

      <xsl:template name="example">
    <xsl:param name="item"/> <xsl:param name="sortField"/> <xsl:for-each select="."> <xsl:sort select="$sortField" data-type="number" /> </xsl:for-each> </xsl:template>

     

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 21, 2009 @ 07:53
    Sebastiaan Janssen
    0

    Actually, you probably don't need the seperate template, just put the for-each instead of the call-template bit. :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies