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..
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.
<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">
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" />
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>
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.
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.
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 !
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 !!
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
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>
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
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 !
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
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
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
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 !!
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
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>
PSdataOut is dataOut ... a typing error !! sorry !
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
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 !
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
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:
/Chriztian
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
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
is working on a reply...