Copied to clipboard

Flag this post as spam?

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


  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 18:04
    Arno L. Kristiansen
    0

    Get the value of an input field using XSLT

    I'm total new in using XSLT .. so I hope somebody can help me..

     

    I want to make a form with a input filed + a submit botton..

    How can I after submitting get the value of the input field into my XSLT..

    The ideer is that the user shell input his customer number and after clicking submit I will take the captured value and search inside of my database for this customer number..

    Hope somebody can help me !!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 19:19
    Jan Skovgaard
    0

    Hi Arno

    I assume you're building the form with XSLT as well, right?

    then you should be able to do something like this..

    <xsl:choose>
    <xsl:when test="umbraco.library:Request('sent') !=''">
    <!-- Do your matchup logic here-->
    </xsl:when>
    <xsl:otherwise>

    <form action="" method="post">
    <input name="sent" value="1" />

    <!-- the rest of your form-->


    </form>

    </xsl:otherwise>
    </xsl:choose>

    When the form is submittted the "sent" value is not empty and therefore the when part will be executed.

    You can use the same extension as above to request the values from the other input elements.

    Hope this helps.

    Please be aware though that if you're trying to do anything more "advanced" logic you should probably look into using a user control or making a Razor macro instead.

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 19:40
    Arno L. Kristiansen
    0

    Hi Jan

    Yes I will do it with XSLT..

    how do I afterwards get the value inside sent ??

    See ex

    <xsl:choose>
        <xsl:when test="umbraco.library:Request('sent') !=''">
        <!-- Do your matchup logic here-->
        <xsl:for-each select="sql:GetDataSet('PKTRConnectionString', 'select * from tbShops where no = ??sent??', 'dataOut')//dataOut">

        <ul>
          <li><xsl:value-of select="CompanyName"/> </li>
          </ul>
       </xsl:for-each>   
       </xsl:when>   
      </xsl:choose>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 19:48
    Jan Skovgaard
    0

    If your form's input field looks like this

    <input type="text" name="CompanyName" />

    Then you can fetch the value using the umbraco.library:Request() extension like this <xsl:value-of select="umbraco.library:Request('CompanyName')" />

    This will write out the value of the input field.

    You can also assign the value to a variable by doing <xsl:variable name="CompanyName" select="umbraco.library:Request('CompanyName')" />

    Then you can use the variable to do your comparison. When you use the variable you should be aware that you need to call it using a dollar sign. If for instance you want to write out the value you can do it like this <xsl:value-of select="$CompanyName" />

    Hope this helps.

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 19:59
    Arno L. Kristiansen
    0

    Ok... it helps me a bit..

    But do you know how a set my parameter in the sql ?? 

    I try this but it does not work :

     <xsl:choose>
        <xsl:when test="umbraco.library:Request('CustId') !=''">        
        <xsl:for-each select="sql:GetDataSet('PKTRConnectionString', 'select * from tbShops where no = $CustId', 'dataOut')//PSdataOut">
        <ul>
          <li><xsl:value-of select="CompanyName"/> </li>
          </ul>
       </xsl:for-each>   
       </xsl:when>   
      </xsl:choose>

    the ideer is that the user of the webpages capture his customer no and I show him what companyname I have in my database ! 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 20:17
    Jan Skovgaard
    0

    Hi Arno

    You need to create the variable $CustId before you call it.
    <xsl:variable name="$CustId" select="umbraco.library:Request('CustId')" />

    I must admit that I don't think the value will be submitted when you enter the string like above. Maybe you need to
    create the parameter in a variable as well...like this


    <xsl:when test="umbraco.library:Request('CustId') !=''">
    <xsl:variable name="$CustId" select="umbraco.library:Request('CustId')" />
    <xsl:variable name="params">
    <xsl:text>'PKTRConnectionString', 'select * from tbShops where no =</xsl:text>
    <xsl:value-of select="$CustId" />
    <xsl:text>', 'dataOut'</xsl:text>
    </xsl:variable>

    <xsl:for-each select="sql:GetDataSet($params)//PSdataOut">
    <li>
    <xsl:value-of select="CompanyName" />
    </li>
    </xsl:for-each>

    </xsl:when>

    I tink this should work...try to give it a spin :)

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 21:04
    Arno L. Kristiansen
    0

    stranges !! 

     

    No error when I save the xslt file in umbraco but when I what to see the page in the browser it comes with this error : Error parsing XSLT file

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 21:12
    Jan Skovgaard
    0

    Hi Arno

    Well if the syntax is correct it will not give an error when saved.

    To figure out what is going on you can add ?umbdebugshowtrace=1 to the url of the page, which will give you a stack trace. Error messages will be marked with red.

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 21:23
    Arno L. Kristiansen
    0

    OK !!! Now I can see its my GetDataSet metode that has a problem because it does not have 1 parameter...

    soo it looks like the xslt is working.... thanks !!

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 21:38
    Jan Skovgaard
    0

    Hi Arno

    You're welcome.

    Don't hesitate to ask further questions if you're in doubt about anything.

    You could also uncomment the for-each loop and simply write out the content of the $params variable we created in the above example to see if the string is being rendered correctly with the correct value just to be 100% sure that it is correct.

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 22:00
    Arno L. Kristiansen
    0

    Hi again Ja

    Thanks again..

    That is what im currently is trying, I get no data back for my database, but also no error any longer ... stranges !!

    <xsl:variable name="CustId" select="umbraco.library:Request('CustId')" />  
      <xsl:variable name="params">
              <xsl:text>'select * from tbShops where CustId =</xsl:text>
              <xsl:value-of select="$CustId" />
              <xsl:text>'</xsl:text>
          </xsl:variable>
      
      
      
      <xsl:for-each select="sql:GetDataSet('PKTRConnectionString',$params,'dataOut')//dataOut">
        <ul>
          <li><xsl:value-of select="CompanyName"/> </li>
          </ul>
      </xsl:for-each>

     

    this gives me no error but also no data back..

    if I do it like this:

    <xsl:variable name="CustId" select="umbraco.library:Request('CustId')" />  
      <xsl:variable name="params">
              <xsl:text>'select * from tbShops where CustId =</xsl:text>
              <xsl:value-of select="$CustId" />
              <xsl:text>'</xsl:text>
          </xsl:variable>
      
      
      
      <xsl:for-each select="sql:GetDataSet('PKTRConnectionString','select * from tbShops where CustId = 96102','dataOut')//PSdataOut">
        <ul>
          <li><xsl:value-of select="CompanyName"/> </li>
          </ul>
      </xsl:for-each>

    Reslut show from code

    <ul xmlns:sql="urn:sql">

      <li>DagliĀ“Brugsen Bispeparken                         </li>

    </ul>

    so it looks like a have a problem pasing this $params correctly to the for-each ?? stranges
    /arno

     


  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 22:02
    Arno L. Kristiansen
    0

    PSdataOut is dataOut ... a typing error !! sorry !

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 22:05
    Jan Skovgaard
    0

    Hi Arno

    Does that mean it works now? :)

    Otherwise I would like to see what is returned when you write out the content of $params like <xsl:value-of select="$params" />

    /Jan

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 05, 2012 @ 22:13
    Arno L. Kristiansen
    0

    this is what it returns : 'select * from tbShops where CustId =96101'

    And my code looe like this...

     <xsl:variable name="params">
              <xsl:text>'select * from tbShops where CustId =xsl:text>
              <xsl:value-of select="$CustId" />
              <xsl:text>'xsl:text>
          xsl:variable>  
      
      <xsl:value-of select="$params" />
      
      <xsl:for-each select="sql:GetDataSet('PKTRConnectionString',$params,'dataOut')//dataOut">
        <ul>
          <li><xsl:value-of select="CompanyName"/> li>
          ul>
      xsl:for-each>

    I had to changes it a bit because the GetDataSet metode expects 3 parameteres... but again do I pass not the $params but the
     
    'select * from tbShops where CustId =96101' I get a result.. but with $params no result !

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 05, 2012 @ 23:00
    Jan Skovgaard
    0

    Hmmm

    What happens if you include all the params in the $params variable, like I did in one of the initial posts and then do something like

    <xsl:for-each select="sql:GetDataSet(string($params))">
    </xsl:for-each>

    does that work?

    /Jan

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jan 05, 2012 @ 23:33
    Chriztian Steinmeier
    1

    Hi Arno (+ Jan)

    I just saw this and have two suggestions:

    1. Don't include the single quotes in the string - they're used to encapsulate a literal string.

    2. Use concat() to build the params variable instead:

    <xsl:variable name="params" select="concat('select * from tbShops where CustId = ', $CustId)" />

    /Chriztian

  • Arno L. Kristiansen 43 posts 63 karma points
    Jan 06, 2012 @ 10:39
    Arno L. Kristiansen
    0

    Hi Jan and Chriztian ...

    100000000 thanks for the help with this..

    To remove the quotes from the params variable was the solution... and the only thing I didn't try ;-)

    Now everything is running and working... thanks again 

    /arno

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 06, 2012 @ 16:58
    Jan Skovgaard
    0

    Hi Arno

    Glad to hear you managed to sort it out. I should have thought about removing the plings myself and using concat. Mr. Steinmeier to the resuce :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft