Re: [xsl] Unique html name, id, and for form fields

Subject: Re: [xsl] Unique html name, id, and for form fields
From: Jeremy Marzka <jmarzka@xxxxxxxxx>
Date: Wed, 11 May 2005 09:27:39 -0400
Thanks for your reply.

I understand the unique id part and added an id field to my xml
document used with the select box. Now how can I create unique id's,
for's, and name's that can later be accessed in some organized way by
a server side script. For example I would like to be able to determine
the value of the select box for the row of the Go button that was
clicked.

I've created a more specific example to use, I'm just looking for a
more generic way of doing it. I was thinking this could be done by
just calling a generic repeat template but I am not sure where to
start.

Desired output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Test</title>
  </head>
  <body>
    <form action="transform.aspx" method="post">
      <div id="status_table_1">

        <h2>Deleted</h2>
        <table border="1" cellpadding="4" width="650px">
          <tr>
            <td width="25%">
              <strong>Request Date</strong>
            </td>
            <td width="15%">
              <strong>Change Title</strong>

            </td>
            <td width="15%">
              <strong>Status</strong>
            </td>
            <td width="45%">
              <strong>Action</strong>
            </td>
          </tr>

        </table>
        <br>
      </div>
      <div id="status_table_2">
        <h2>Approved</h2>
        <table border="1" cellpadding="4" width="650px">
          <tr>
            <td width="25%">

              <strong>Request Date</strong>
            </td>
            <td width="15%">
              <strong>Change Title</strong>
            </td>
            <td width="15%">
              <strong>Status</strong>

            </td>
            <td width="45%">
              <strong>Action</strong>
            </td>
          </tr>
          <tr id="status_table_2:ac_request_1">
            <td>2005-03-09 9:12:44</td>
            <td>test2</td>

            <td>Approved</td>
            <td>
              <label for="status_table_2:ac_request_1:action">Action:</label>
              <select id="status_table_2:ac_request_1:action"
name="ac_request_1:action">
                <option value="0">Select an action</option>
                <option id="status_table_2:ac_request_1:action_list_1"
value="">View</option>
                <option id="status_table_2:ac_request_1:action_list_2"
value="">Delete</option>

                <option id="status_table_2:ac_request_1:action_list_3"
value="">Approve</option>
                <option id="status_table_2:ac_request_1:action_list_4"
value="">Deny</option>
                <option id="status_table_2:ac_request_1:action_list_5"
value="">Add Comments</option>
                <option id="status_table_2:ac_request_1:action_list_6"
value="">Add Attachments</option>
              </select>
              <span id="status_table_2:ac_request_1:test">test:</span>

              <input type="submit"
name="status_table_2:ac_request_1:submit" value="Go">
            </td>
          </tr>
          <tr id="status_table_2:ac_request_2">
            <td>2005-03-09 9:14:15</td>
            <td>test23</td>
            <td>Approved</td>

            <td>
              <label for="status_table_2:ac_request_2:action">Action:</label>
              <select id="status_table_2:ac_request_2:action"
name="ac_request_2:action">
                <option value="0">Select an action</option>
                <option id="status_table_2:ac_request_2:action_list_1"
value="">View</option>
                <option id="status_table_2:ac_request_2:action_list_2"
value="">Delete</option>
                <option id="status_table_2:ac_request_2:action_list_3"
value="">Approve</option>

                <option id="status_table_2:ac_request_2:action_list_4"
value="">Deny</option>
                <option id="status_table_2:ac_request_2:action_list_5"
value="">Add Comments</option>
                <option id="status_table_2:ac_request_2:action_list_6"
value="">Add Attachments</option>
              </select>
              <span id="status_table_2:ac_request_2:test">test:</span>
              <input type="submit"
name="status_table_2:ac_request_2:submit" value="Go">
            </td>

          </tr>
        </table>
        <br>
      </div>
      <div id="status_table_3">
        <h2>Denied</h2>
        <table border="1" cellpadding="4" width="650px">
          <tr>

            <td width="25%">
              <strong>Request Date</strong>
            </td>
            <td width="15%">
              <strong>Change Title</strong>
            </td>
            <td width="15%">
              <strong>Status</strong>

            </td>
            <td width="45%">
              <strong>Action</strong>
            </td>
          </tr>
          <tr id="status_table_3:ac_request_1">
            <td>2005-03-09 9:14:15</td>
            <td>test3</td>

            <td>Denied</td>
            <td>
              <label for="status_table_3:ac_request_1:action">Action:</label>
              <select id="status_table_3:ac_request_1:action"
name="ac_request_1:action">
                <option value="0">Select an action</option>
                <option id="status_table_3:ac_request_1:action_list_1"
value="">View</option>
                <option id="status_table_3:ac_request_1:action_list_2"
value="">Delete</option>

                <option id="status_table_3:ac_request_1:action_list_3"
value="">Approve</option>
                <option id="status_table_3:ac_request_1:action_list_4"
value="">Deny</option>
                <option id="status_table_3:ac_request_1:action_list_5"
value="">Add Comments</option>
                <option id="status_table_3:ac_request_1:action_list_6"
value="">Add Attachments</option>
              </select>
              <span id="status_table_3:ac_request_1:test">test:</span>

              <input type="submit"
name="status_table_3:ac_request_1:submit" value="Go">
            </td>
          </tr>
        </table>
        <br>
      </div>
      <div id="status_table_4">
        <h2>Completed</h2>

        <table border="1" cellpadding="4" width="650px">
          <tr>
            <td width="25%">
              <strong>Request Date</strong>
            </td>
            <td width="15%">
              <strong>Change Title</strong>
            </td>

            <td width="15%">
              <strong>Status</strong>
            </td>
            <td width="45%">
              <strong>Action</strong>
            </td>
          </tr>
          <tr id="status_table_4:ac_request_1">

            <td>2005-03-09 9:11:56</td>
            <td>test</td>
            <td>Completed</td>
            <td>
              <label for="status_table_4:ac_request_1:action">Action:</label>
              <select id="status_table_4:ac_request_1:action"
name="ac_request_1:action">
                <option value="0">Select an action</option>

                <option id="status_table_4:ac_request_1:action_list_1"
value="">View</option>
                <option id="status_table_4:ac_request_1:action_list_2"
value="">Delete</option>
                <option id="status_table_4:ac_request_1:action_list_3"
value="">Approve</option>
                <option id="status_table_4:ac_request_1:action_list_4"
value="">Deny</option>
                <option id="status_table_4:ac_request_1:action_list_5"
value="">Add Comments</option>
                <option id="status_table_4:ac_request_1:action_list_6"
value="">Add Attachments</option>

              </select>
              <span id="status_table_4:ac_request_1:test">test:</span>
              <input type="submit"
name="status_table_4:ac_request_1:submit" value="Go">
            </td>
          </tr>
        </table>
        <br>
      </div>

    </form>
  </body>
</html>

-------- test.xsl --------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

	<xsl:output method="html" indent="yes" encoding="utf-8"
		doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; />

    <xsl:variable name="actions" select="document ('actions.xml')" />
    <xsl:variable name="statuses" select="document ('status.xml')" />
    <xsl:variable name="ac_requests" select="/" />

    <xsl:template match="/">
        <html>
            <head>
                <title>Test</title>
            </head>
            <body>
                <form action="transform.aspx" method="post">
                    <xsl:for-each select="$statuses/statuses/status">
					<xsl:variable name="status" select="." />
					<xsl:variable name="parent1" select="concat('status_table_',
position())" />
					<div id="{$parent1}">
						<h2><xsl:value-of select="$status/@status" /></h2>
	                    <table border="1" cellpadding="4" width="650px">
	                        <tr>
	                            <td width="25%"><strong>Request
Date</strong></td>
	                            <td width="15%"><strong>Change
Title</strong></td>
	                            <td width="15%"><strong>Status</strong></td>
	                            <td width="45%"><strong>Action</strong></td>
	                        </tr>

	                        <xsl:for-each
select="$ac_requests/ac_requests/ac_request[@status =
$status/@status]">
	                            <xsl:variable name="acreq" select="." />
                            	<xsl:variable name="parent2"
select="concat('ac_request_', position())" />
	                            <tr id="{$parent1}:{$parent2}">
	                                <td><xsl:value-of
select="@request_date" /></td>
	                                <td><xsl:value-of
select="@change_title" /></td>
	                                <td><xsl:value-of select="@status" /></td>
	                                <td>
	                                    <label
for="{$parent1}:{$parent2}:action">Action:</label>
	                                    <select
id="{$parent1}:{$parent2}:action" name="{$parent2}:action">
	                                        <option value="0">Select an
action</option>
	                                        <xsl:for-each
select="$actions/actions/action">

	                                            <option
id="{$parent1}:{$parent2}:action_list_{position()}"
value="{$acreq/@ID}">
	                                                <xsl:value-of
select="@action" />
	                                            </option>

	                                        </xsl:for-each>

	                                    </select>
										<span id="{$parent1}:{$parent2}:test">test:</span>
	                                    <input type="submit"
name="{$parent1}:{$parent2}:submit" value="Go" />
	                                </td>
	                            </tr>
	                        </xsl:for-each>
	                    </table>
	                    <br />
	                </div>
                    </xsl:for-each>
                </form>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

-------- test.xml --------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<ac_requests>
	<ac_request id="1" request_date="2005-03-09 9:11:56"
change_title="test" status="Completed"/>
	<ac_request id="2" request_date="2005-03-09 9:12:44"
change_title="test2" status="Approved"/>
	<ac_request id="3" request_date="2005-03-09 9:14:15"
change_title="test3" status="Denied"/>
	<ac_request id="4" request_date="2005-03-09 9:14:15"
change_title="test23" status="Approved"/>
</ac_requests>

-------- actions.xml --------
<actions>
	<action action_id="1" action="View"/>
	<action action_id="2" action="Delete"/>
	<action action_id="3" action="Approve"/>
	<action action_id="4" action="Deny"/>
	<action action_id="5" action="Add Comments"/>
	<action action_id="6" action="Add Attachments"/>
</actions>

-------- status.xml --------
<statuses>
	<status status_id="1" status="Deleted"/>
	<status status_id="2" status="Approved"/>
	<status status_id="3" status="Denied"/>
	<status status_id="4" status="Completed"/>
</statuses>

On 5/10/05, omprakash.v@xxxxxxxxxxxxx <omprakash.v@xxxxxxxxxxxxx> wrote:
>
>
> Hi,
>          Please find below the xsl stylesheet that does what you want.
> Since you want 1 select box for each AC_Request in your source xml, there
> has to be a distinguishing factor in your source xml. I could only find
> that the time differed in the RequestDate attribute in the 3 AC_Request
> elements. Therefore I have used the concatenation of the RequestDate and
> the result of the generate-id function as the value of each option.
>
> The only problem I can foresee is due to the ever-changing nature of time,
> the option values too would keep changing resulting in your having to
> change your server side programs each time the source xml changes. I would
> suggest you add another attribute to that is unique across AC_REQUEST and
> is more deterministic.
>
> Hope this helps.
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet version="1.0" xmlns:xsl
> ="http://www.w3.org/1999/XSL/Transform";>
>
>            <xsl:output method="html" indent="yes" encoding="utf-8"
>                      doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
>                      doctype-system
> ="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; />
>
>                      <xsl:variable name="priorities" select="document
> ('priority.xml')" />
>
>                      <xsl:template match="/">
>                                <html>
>                                <head>
>                                           <title>Test</title>
>                                </head>
>                                <body>
>                                <form action="transform.aspx" method="post">
>                                <table border="1" cellpadding="4">
>                                           <tr>
>                                                     <td><strong>Request
> Date</strong></td>
>                                                     <td><strong>Change
> Title</strong></td>
>
> <td><strong>Status</strong></td>
>
> <td><strong>Action</strong></td>
>                                           </tr>
>                                           <xsl:for-each select
> ="/AC_Requests/AC_Request">
>
>                                           <xsl:variable name="acreq" select
> ="."/>
>                                           <tr>
>                                                     <td><xsl:value-of
> select="@RequestDate" /></td>
>                                                     <td><xsl:value-of
> select="@ChangeTitle" /></td>
>                                                     <td><xsl:value-of
> select="@StatusID" /></td>
>                                                     <td>
>                                                               <label for
> ="action">Priority: </label>
>                                                               <select id
> ="action" name="action">
>
> <option value="0">Select an action</option>
>
> <xsl:for-each select="$priorities/priorities/priority">
>
> <xsl:message><td><xsl:value-of select="concat(normalize-space
> ($acreq/@RequestDate), generate-id(.))" /></td></xsl:message>
>
>       <option value="{concat(generate-id(.), normalize-space
> ($acreq/@RequestDate))}"><xsl:value-of
> select="@priority" /></option>
>
> </xsl:for-each>
>                                                               </select>
>                                                               <input type
> ="submit" name="submit" value="Go" />
>                                                     </td>
>                                           </tr>
>                                           </xsl:for-each>
>                                </table>
>                                </form>
>                                </body>
>                                </html>
>
>                      </xsl:template>
>
> </xsl:stylesheet>
>
> Cheers,
> Omprakash.V
>
>                     Jeremy Marzka
>                     <jmarzka@gmai        To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>                     l.com>               cc:     (bcc: omprakash.v/Polaris)
>                                          Subject:     [xsl] Unique html
name, id, and for form fields
>                     05/11/2005
>                     02:00 AM
>                     Please
>                     respond to
>                     xsl-list
>
>
> I am working on creating an html report from two xml sources. The
> first source is the xml that needs to be displayed in the report. The
> second source is used to populate a select box. The problem i'm having
> is with the multiple for-each's necessary to do this. In the
> for-each's I need to generate unique id's, name's and for's in a way
> that they can be processed server side later.
>
> Here is what I currently have:
>
> ----test.xsl----
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet version="1.0" xmlns:xsl="
> http://www.w3.org/1999/XSL/Transform";>
>
>            <xsl:output method="html" indent="yes" encoding="utf-8"
>                      doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
>                      doctype-system="
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; />
>
>                      <xsl:variable name="priorities" select="document
> ('priorities.xml')" />
>
>                      <xsl:template match="/">
>                                <html>
>                                <head>
>                                           <title>Test</title>
>                                </head>
>                                <body>
>                                <form action="transform.aspx" method="post">
>                                <table border="1" cellpadding="4">
>                                           <tr>
>                                                     <td><strong>Request
> Date</strong></td>
>                                                     <td><strong>Change
> Title</strong></td>
>
> <td><strong>Status</strong></td>
>
> <td><strong>Action</strong></td>
>                                           </tr>
>                                           <xsl:for-each select
> ="/AC_Requests/AC_Request">
>                                           <tr>
>                                                     <td><xsl:value-of
> select="@RequestDate" /></td>
>                                                     <td><xsl:value-of
> select="@ChangeTitle" /></td>
>                                                     <td><xsl:value-of
> select="@StatusID" /></td>
>                                                     <td>
>                                                               <label for
> ="action">Priority: </label>
>                                                               <select id
> ="action" name="action">
>
> <option value="0">Select an action</option>
>
> <xsl:for-each select="$priorities/priorities/priority">
>
>       <option value="{@priority_id}"><xsl:value-of
> select="@priority" /></option>
>
> </xsl:for-each>
>                                                               </select>
>                                                               <input type
> ="submit" name="submit" value="Go" />
>                                                     </td>
>                                           </tr>
>                                           </xsl:for-each>
>                                </table>
>                                </form>
>                                </body>
>                                </html>
>
>                      </xsl:template>
>
> </xsl:stylesheet>
>
> ---- test.xml ----
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="test.xsl"?>
> <AC_Requests>
>            <AC_Request RequestDate="2005-03-09 9:11:56" ChangeTitle="test"
> StatusID="3"/>
>            <AC_Request RequestDate="2005-03-09 9:12:44" ChangeTitle="test"
> StatusID="3"/>
>            <AC_Request RequestDate="2005-03-09 9:14:15" ChangeTitle="test"
> StatusID="2"/>
> </AC_Requests>
>
> ---- priorities.xml ----
> <?xml version="1.0"?>
> <priorities>
>            <priority priority_id="1" priority="Hold"/>
>            <priority priority_id="2" priority="High"/>
>            <priority priority_id="3" priority="Med"/>
>            <priority priority_id="4" priority="Low"/>
> </priorities>
>
> ---- OUTPUT ----
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> <html>
>   <head>
>     <META http-equiv="Content-Type" content="text/html; charset=utf-8">
>     <title>Test</title>
>   </head>
>   <body>
>     <form action="transform.aspx" method="post">
>       <table border="1" cellpadding="4">
>
>         <tr>
>           <td>
>             <strong>Request Date</strong>
>           </td>
>           <td>
>             <strong>Change Title</strong>
>           </td>
>           <td>
>
>             <strong>Status</strong>
>           </td>
>           <td>
>             <strong>Priority</strong>
>           </td>
>           <td>
>             <strong>Action</strong>
>
>           </td>
>         </tr>
>         <tr>
>           <td>2005-03-09 9:11:56</td>
>           <td>test</td>
>           <td>3</td>
>           <td>
>
>             <select id="action" name="action">
>               <option value="0">Select an action</option>
>               <option value="1">Hold</option>
>               <option value="2">High</option>
>               <option value="3">Med</option>
>               <option value="4">Low</option>
>
>             </select>
>           </td>
>           <td>
>             <input type="submit" name="submit" value="Go">
>           </td>
>         </tr>
>         <tr>
>           <td>2005-03-09 9:12:44</td>
>
>           <td>test</td>
>           <td>3</td>
>           <td>
>             <select id="action" name="action">
>               <option value="0">Select an action</option>
>               <option value="1">Hold</option>
>               <option value="2">High</option>
>
>               <option value="3">Med</option>
>               <option value="4">Low</option>
>             </select>
>           </td>
>           <td>
>             <input type="submit" name="submit" value="Go">
>           </td>
>         </tr>
>
>         <tr>
>           <td>2005-03-09 9:14:15</td>
>           <td>test</td>
>           <td>2</td>
>           <td>
>             <select id="action" name="action">
>               <option value="0">Select an action</option>
>
>               <option value="1">Hold</option>
>               <option value="2">High</option>
>               <option value="3">Med</option>
>               <option value="4">Low</option>
>             </select>
>           </td>
>           <td>
>
>             <input type="submit" name="submit" value="Go">
>           </td>
>         </tr>
>       </table>
>     </form>
>   </body>
> </html>
>
> This e-Mail may contain proprietary and confidential information and is sent
for the intended recipient(s) only.
> If by an addressing or transmission error this mail has been misdirected to
you, you are requested to delete this mail immediately.
> You are also hereby notified that any use, any form of reproduction,
dissemination, copying, disclosure, modification,
> distribution and/or publication of this e-mail message, contents or its
attachment other than by its intended recipient/s is strictly prohibited.
>
> Visit Us at http://www.polaris.co.in

Current Thread