Copied to clipboard

Flag this post as spam?

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


  • Palle Hansen 143 posts 396 karma points
    Sep 01, 2014 @ 11:33
    Palle Hansen
    0

    Make a search string using RequestFrom

    Hi.

    I'm trying to make a page to show some results after a visitor hit submit.

    My form is a simple form with 4 selects and method is post.
    But when I try to show the result nothing shows.

    I'm using 4 variables and they contain right data based on the selects, and the values from the selects are ID's.<

    Variables:
    <xsl:variable name="type" select="umbraco.library:RequestForm('type')"/>
    <xsl:variable name="totalvaegt" select="umbraco.library:RequestForm('totalweight')"/>
    <xsl:variable name="lenght" select="umbraco.library:RequestForm('lenght')"/>
    <xsl:variable name="aksler" select="umbraco.library:RequestForm('aksler')"/>


    Here i my for-each line:
    <xsl:for-each select="umbraco.library:GetXmlNodeById(1168)/descendant-or-self::*//Product [@isDoc][wwtype/MultiNodePicker/nodeId=$type and wwtotalvaegt/MultiNodePicker/nodeId=$totalvaegt and wwstorrelse/MultiNodePicker/nodeId=$lenght and wwaklser/MultiNodePicker/nodeId=$aksler]">

     

    Does any one have a clue?

    /Palle

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 01, 2014 @ 11:52
    Chriztian Steinmeier
    0

    Hi Palle,

    Using and to build the query, you will only get a result if all four selects match a value on a specific node (which you may of course be very well aware of - just making sure that's the intended behavior :-)

    The "length" parameter is spelled "lenght" - it's consistent, so as long as the form input's name attribute is also spelled like that, it should work. (And if it isn't, that could very well be the problem you're not seeing any results).

    One way to debug this would be to use individual results, like this:

    <xsl:variable name="type" select="umbraco.library:RequestForm('type')"/>
    <xsl:variable name="totalvaegt" select="umbraco.library:RequestForm('totalweight')"/>
    <xsl:variable name="lenght" select="umbraco.library:RequestForm('lenght')"/>
    <xsl:variable name="aksler" select="umbraco.library:RequestForm('aksler')"/>
    
    <xsl:variable name="products" select="umbraco.library:GetXmlNodeById(1168)//Product[@isDoc]" />
    
    <xsl:variable name="productsByType"   select="$products[wwtype//nodeId = $type]" />
    <xsl:variable name="productsByWeight" select="$products[wwtotalvaegt//nodeId = $totalvaegt]" />
    <xsl:variable name="productsBySize"   select="$products[wwstorrelse//nodeId = $lenght]" />
    <xsl:variable name="productsByAxels"  select="$products[wwaklser//nodeId = $aksler]" />
    
    <xsl:for-each select="$productsByType | $productsByWeight | $productsBySize | $productsByAxels">
        <!-- Do something -->
    </xsl:for-each>
    

    This way, you'll get results for those that work - and you'll be able to see where the results differ from what you expect...

    /Chriztian

  • Palle Hansen 143 posts 396 karma points
    Sep 01, 2014 @ 12:47
    Palle Hansen
    0

    Hi Chriztian.

    Thanks for your reply.
    I need all four varibles to be true to show a product.

    Should I replace  | with anything else to do that, or is it the same as and? 

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 01, 2014 @ 13:17
    Chriztian Steinmeier
    0

    Hi Palle,

    No - the pipe is used for joining nodesets, but now that you have the individual sets you can try this:

    <xsl:for-each select="$products
        [@id = $productsByType/@id]
        [@id = $productsByWeight/@id]
        [@id = $productsBySize/@id]
        [@id = $productsByAxels/@id]"
    >
      <!-- Do stuff --> 
    </xsl:for-each>
    

    (Picking any product that also exists in all of the specific sets)

    BTW: I just noticed that the wwaklser property is misspelled (should be wwaksler, right?) in the queries - is that the way its alias is spelled?

    /Chriztian

  • Palle Hansen 143 posts 396 karma points
    Sep 01, 2014 @ 14:01
    Palle Hansen
    0

    Works like a charm.
    Thanks

     

    /Palle 

  • Palle Hansen 143 posts 396 karma points
    Sep 02, 2014 @ 19:23
    Palle Hansen
    0

    Hi Chriztian.

    Got one more, if it's okay.

    I want to count number of products that's found. The count is coming from another page and i use Ajax to get it.

    This is my count:
    <xsl:value-of select="count(msxml:node-set($products [@id = $productsByType/@id] [@id = $productsByWeight/@id] [@id = $productsBySize/@id] [@id = $productsByAxels/@id]))"/>
    But it returs 0 no matter what I'm searching for - and that's not right.

    If I change the count to this: 
    <xsl:value-of select="count(msxml:node-set($productsByType | $productsByWeight | $productsBySize | $productsByAxels)"/>
    it's counting, but I need a count if all four variables are true.

    Here's my ajax:

    $('#aksler').on('change', function () {

        var postData = $(this).serializeArray();

        var formURL = "/counttrailers.aspx";

        $.ajax({

            url: formURL,

            type: "POST",

            data: postData,

            success: function (data, textStatus, jqXHR) {

                $("#result").html(data);

            },

            error: function (jqXHR, textStatus, errorThrown) {}

        });

    }); 

     

    Can you see what I'm missing?

    /Palle

     

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 02, 2014 @ 21:46
    Chriztian Steinmeier
    0

    Hi Palle,

    If you're using my other code from earlier, there's no need to use the node-set() function - just counting the nodes in the combined set should do it:

    <xsl:value-of select="count($products[@id = $productsByType/@id][@id = $productsByWeight/@id][@id = $productsBySize/@id][@id = $productsByAxels/@id])" />
    

    Any particular reason for having thrown the node-set function in there?

    /Chriztian

  • Palle Hansen 143 posts 396 karma points
    Sep 05, 2014 @ 08:13
    Palle Hansen
    0

    Hi Chriztian.

    The node-set() was just for trying. It made no difference for the outcome.

    The problem is that this line: count($products[@id = $productsByType/@id][@id = $productsByWeight/@id][@id = $productsBySize/@id][@id = $productsByAxels/@id]) - returns 0 when the result comes from my ajax call and I've checked that there is product that fits my search.

    I can't see that my ajax call is wrong, but mabye I'm missing something. 

    /Palle 

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 05, 2014 @ 09:42
    Chriztian Steinmeier
    0

    Hi Palle,

    If you just do <xsl:value-of select="count($productsByType | $productsByWeight | $productsBySize | $productsByAxels)" /> you get a number, if I understand correct?

    This is the total number of nodes matched - so even if the same node exist in all of the variables, it will only count as one.

    Also, if you're getting a number from that count, it's highly likely that there is in fact no node(s) that matches all of them, so you should try to debug, by listing the nodes of each variable then:

    <div>
        <h1>$productsByType (<xsl:value-of select="count($productsByType)" />)</h1>
        <xsl:apply-templates select="$productsByType" mode="debug" />
    </div>
    <div>
        <h1>$productsByWeight (<xsl:value-of select="count($productsByWeight)" />)</h1>
        <xsl:apply-templates select="$productsByWeight" mode="debug" />
    </div>
    <!-- Same for the others -->
    
    <!-- Debug template -->
    <xsl:template match="*[@isDoc]" mode="debug">
        <p>
            <xsl:value-of select="concat('ID: ', @id, ' Name: ', @nodeName)" />
        </p>
    </xsl:template>
    

    This should let you inspect the contents and see if you're getting what you expect.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft