XSLT for Beginners

Hey guys,

I'm in desperate need for help!  Isn't everyone that post though :)

Ok.  I'm really new to XSLT so I'm guessing the problem I'm having is easily overcome... I hope cos I need to get this thing finished in about 5 hours.  Everything is working on my webpage except for one thing...  I need to add a button in the XSLT.  The code supplied works fine except for the button section.  It displays all the products, descriptions,etc...  What I need as well, is to have a button for each product that has the following code attached to it

Context.Items("ProductID") = @name
                             (the name of the current product name)
Server.Transfer("AddToCart.aspx")

So it calls the addtocart page and the code in that adds the product to the shopping cart.

Ok, in the code below, I've tried heaps of things to get this working but I just can't figure it out.

Guys, any help here ASAP would be greatly appreciated!  I'm a the business end of the rope at the moment so I'm really struggling. :(

Look forward to a solution.
oMavericko

[code]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version= "1.0">
      <xsl:template match="/">
            
            <xsl:for-each select="/productlist/product">
                  <TABLE width="75%" align="center" border="1">
                        <tr>
                              <td>Name: </td>
                              <td><xsl:apply-templates select="name"/></td>
                              <td RowSpan = "4" width= "0"> <xsl:apply-templates select="image"/></td>
                        </tr>
                        <tr>
                              <td>Code: </td>
                              <td><xsl:apply-templates select="code"/>t</td>
                        </tr>
                        <tr>
                              <td>Category: </td>
                              <td><xsl:apply-templates select="category"/></td>
                        </tr>
                        <tr>
                              <td>Price: </td>
                              <td><xsl:apply-templates select="price"/></td>
                        </tr>
                        <tr>
                              <td>Description: </td>
                              <td><xsl:apply-templates select="description"/></td>
                              <td>
                                    <input type="button" onclick="Context.Items("ProductID") = prodid;Server.Transfer("AddToCart.aspx")" value="Add To Cart"/>
                              </td>
                        </tr>
                  </TABLE>
                  <p/>
            </xsl:for-each>
      </xsl:template>
      
      <xsl:template match="name">
            <b><xsl:value-of select="."/> </b>
      </xsl:template>
                  
      <xsl:template match="code">
            <xsl:value-of select="."/>
      </xsl:template>
      
      <xsl:template match="price">
            $<xsl:value-of select="."/>.00
      </xsl:template>
      
      <xsl:template match="category">
            <xsl:value-of select="."/>
      </xsl:template>
      
      <xsl:template match="description">
            <xsl:value-of select="."/>
      </xsl:template>  
                                  
      <xsl:template match="image">
            <img>
                  <xsl:attribute name="src">
                        <xsl:value-of select="." />
                  </xsl:attribute>
            </img>      
         </xsl:template>
         
</xsl:stylesheet>[/code]
oMaverickoVBAsked:
Who is Participating?
 
ljfernandezCommented:
OK, the solution I'm talking about is something like this, but it will need tweaking. I'm assuming the "." value is the product id.

 <form action="AddToCart.aspx">
<input type="hidden" id="prodID"/>

<xsl:for-each select=".">
<xsl:variable name="prodID"><xsl:value-of select="."/></xsl:variable>

<input type='button' onclick='document.getElementById("prodID").value={$prodID};document.forms[0].submit();' value='Add To Cart'/>
                                    
</xsl:for-each>
</form>

Then in the code behind of AddToCart.aspx, you have to grab the value of request.prodID.
0
 
ljfernandezCommented:
Your problem is the quotes. Try this:

<input type='button' onclick='Context.Items("ProductID") = prodid;Server.Transfer("AddToCart.aspx")' value='Add To Cart'/>
0
 
oMaverickoVBAuthor Commented:
mmm... I tried that.  It didn't work.  I can't seem to get any code to work here.  Is there a bit of test code I could put in there to see if I can get that working.  I'm a VB Programmer, so I'm used to using MSGBOX("test") to see if anything works.  can I do that here?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ljfernandezCommented:
I see. So you are you trying to insert VB.net code here, in the onclick event of the link?
0
 
oMaverickoVBAuthor Commented:
yep, is that possible?  I basically need to pass the current product to a webpage.  Is this possible???  Can you show me a simple how to do this?

cheers
0
 
oMaverickoVBAuthor Commented:
sorry, I don't understand. I thought this was in the XML area?  What do I need to do?  Is there a link I need to follow or anything?
0
 
ljfernandezCommented:
Is the product id in the xml file that you are tranforming?

If so, you could create a hidden form field on the page, in the onclick event have a javascript which passes the value to the hidden field and submits the form to AddToCart.aspx. This file's code behind would then read it and perform the needed action.

Lisa
0
 
oMaverickoVBAuthor Commented:
The product id is the product name in this case.  So it's already in the XML file.  Can you show what code I need to have using the context items and server.transfer code?  I've been told I need to do it this way.

Is it possible for you to show me on my example above?  

Thanks in advance
0
 
oMaverickoVBAuthor Commented:
Ok.  No matter what code I put in the onclick... I'm getting an error.  I put this line of code in just to see if this is where my problem lies...

           <input type='button' onclick='textbox1.text=1'></input>

All I got from this is an error.... not cool.  any reason why?
0
 
ljfernandezCommented:
<input type='button' onclick='textbox1.value=1'></input>
0
 
ljfernandezCommented:
You can put javascript in there, no problem.
0
 
oMaverickoVBAuthor Commented:
ok... I've worked that part out.  I'm using VS.NET and I was using the textbox from the webforms and not the HTML toolbox.  Ok.  So I've worked that little bit out.  

But I'm still lost about how I use those 2 lines of code I need.  One to set that variable and the other to load the other page....

?? Me lost
0
 
ljfernandezCommented:
Is the product id in the xml file that you are tranforming?
0
 
oMaverickoVBAuthor Commented:
The product id is exactly the same as the product name which is being passed.  Is that a problem?
0
 
oMaverickoVBAuthor Commented:
I'm lost dude.  Where do I put that code in?  I'm really new at this.  Is it a simple case of adding that section in somewhere to the code above?
0
 
oMaverickoVBAuthor Commented:
Is it possible for you to add the changes to my code above?  I just need to get this part working and then I can hand it in.  Everything else is working.  The AddToCart page uses the following lines of code:-

Dim prodid as string = Ctype(context.items("ProdId"),String)

and then used the label to get the ProdID:-

lblProductID.Text = ProdID

Thanks
0
 
ljfernandezCommented:
IMO I think your question is too complex for 125pts. The first part goes in the xsl and the second part goes in the code behind for the AddToCart.aspx file.

Lisa
0
 
oMaverickoVBAuthor Commented:
sorry, I don't have any more points.  These are my last points available.  I didn't think it was going to be this much of a problem for you.

Sorry about this then.
0
 
oMaverickoVBAuthor Commented:
Well, I'm still stuck in the same position I was at the start about 3 hours ago.  Thank you for helping anyway.  I honestly don't understand where that code goes but thank you anyway.  I just gotta stick with it and see what happens.  Sorry, I don't have anymore points to give you.


oMavericko
0
 
ljfernandezCommented:
oMavericko,

Hey no problem, I was just saying that it seems the problem is a bit more complex than it seems on the surface. I can't add my code to your code because of the complexities of combining the two technologies that you are trying to use here. As I understand it, the .Net code is executed on the server side before the XSL transform takes place, which means you can't easily put the .net stuff in the html like you can with a regular .aspx page.  Sorry I couldn't be of more help to you. I feel bad taking your points if my answer doesn't help!

Best of luck with your problem,

Lisa
0
 
oMaverickoVBAuthor Commented:
hey, its ok.  I took a punt... it didn't pay off but I guess it kinda showed which way I shouldn't be heading :/

I just find it hard that I can't use those 2 lines of code in the XSL file...  I simply don't have enough knowledge of it to get it done so I'm stuffed now.




thanks anyway
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.