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

Subject: Re: [xsl] Unique html name, id, and for form fields
From: omprakash.v@xxxxxxxxxxxxx
Date: Wed, 11 May 2005 09:20:00 +0530
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