Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2008, 02:20 PM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default unique attribute names for form elements

I'm performing an XSL transformation which creates an editable HTML form based on an input XML file, with each form input element corresponding to each element's attribute in the XML file. The idea is that the user can edit the XML element's attributes by using it's corresponding field in the form. I'm wondering how I would give each form input element a unique ID so I can process it with a JSP. The input XML file could have one element with one attribute, or it could have 100 elements with a dozen attributes, so I'm not sure how I would access all of that information on the JSP without already knowing the names of the form input elements, or even how many elements there are.

Here's part of the code in my XSL

<form method="post" action="edittest2.jsp">
    <table>
        <xsl:for-each select="testcases/testcase/definition/testSteps/testStep">

            <tr>
                <xsl:for-each select="@*">

                    <td align="right"><b><xsl:value-of select="name()"/></b></td>
                    <td>
                    <input type="text" >
                        <xsl:attribute name="id">
                            <xsl:value-of select="name()"/>
                        </xsl:attribute>
                        <xsl:attribute name="value">
                            <xsl:value-of select="."/>
                        </xsl:attribute>
                </input>
                    </td>
                </xsl:for-each>
            </tr>

        </xsl:for-each>


And here is an example of one of my input XML elements
<testStep action="sleep" timeout="500"></testStep>


So, this produces a HTML file with a new row for each testStep and an input field for each attribute of that element. The problem is that there may be 100 <testStep> elements that have an action called "action", so how would I uniquely identify the form elements so I can process them?

The overall idea is to be able to edit the attributes and save the changes back to the original XML using JSP and javabeans.

Thanks for any help, and sorry if I'm not clear enough. This is my first project of this sort and I still have much to learn.

Reply With Quote
  #2 (permalink)  
Old March 16th, 2008, 03:02 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could try

<xsl:attribute name="id">
    <xsl:value-of select="name()"/>
    <xsl:number count="testStep"/>
</xsl:attribute>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old March 16th, 2008, 06:27 PM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the quick response.

So if I did that, then how would I access the values for the form input elements on my JSP page? My understanding is that you would need to call request.getParameter(parameter name) but would this be possible with the solution you provided since I wouldn't know the parameter's name before hand? I assume I would have to go through some sort of loop which will get the values of all the parameters, but what would this look like?

Also, just to make sure I understand what <xsl:number count="testStep"/> is doing, will that append the count of the node to the value of the "id" attribute".

Thanks again for the great help

Reply With Quote
  #4 (permalink)  
Old March 16th, 2008, 07:46 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The code I suggested will create fields called action1, action2, action3 etc. If that's not predictable enough for your application then you'll have to specify what you want to produce. I can't help you write code unless I know what output you want it to generate.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding a unique attribute Navy1991_1 XSLT 1 July 6th, 2008 06:07 PM
Selecting unique set of elements Chamkaur XSLT 1 March 15th, 2007 05:43 AM
Selecting unique value of an attribute and render vinaura XSLT 4 December 18th, 2006 04:35 PM
Safari attribute names getting lowercased ChrisScott Ajax 0 August 1st, 2006 11:42 AM
unique login names and incremental user IDs krstofer Classic ASP Basics 8 March 11th, 2004 10:55 AM



All times are GMT -4. The time now is 11:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.