Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2008, 02:20 PM
Registered User
 
Join Date: Mar 2008
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.

 
Old March 16th, 2008, 03:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old March 16th, 2008, 06:27 PM
Registered User
 
Join Date: Mar 2008
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

 
Old March 16th, 2008, 07:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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