Click to See Complete Forum and Search --> : [RESOLVED] Populate form field attributes via XSL?


semi-sentient
10-16-2006, 12:29 PM
I'm building an XSL in which I need to be able to put certain XML data (from elements) into form field attributes. Here is my XSL (part of it, at least):

<xsl:for-each select="result/accounts/account">
<xsl:sort select="name" />
<tr>
<td><input type="checkbox" id="@id" value="@id" /></td>
<td><label for="@id"><xsl:value-of select="name" /></label></td>
<td><xsl:value-of select="modDate" /></td>
<td><xsl:value-of select="modBy" /></td>
<td><xsl:value-of select="comments" /></td>
<td>[<a href="javascript:void(0);">edit</a>]</td>
</tr>
</xsl:for-each>


So, my XML file has an element named <id> in each child node that contains the information I need. Based on that, I would like to make that the unique ID of the form field and also set that as the fields value such that my input box is as follows:

...<input type="checkbox" id="10" value="10" />...
...<input type="checkbox" id="11" value="11" />...
... and so on...

How would I go about accomplishing this? Thanks in advance.

semi-sentient
10-16-2006, 12:44 PM
Here is an example of what I'm pulling in, and what I'd like the results to be based on that:

<result>
<accounts>
<account>
<name>Company 1</name>
<id>1</id>
<modBy>user</modBy>
<modDate>2006-07-03T09:40-05:00</modDate>
<comments>Some comment</comments>
</account>
<account>
<name>Company 2</name>
<id>2</id>
<modBy>user</modBy>
<modDate>2006-06-30T14:45-05:00</modDate>
<comments>Some comment</comments>
</account>
</accounts>
</result>

The result I'd like is as follows:

<tr>
<td><input type="checkbox" id="1" value="1" /></td>
<td><label for="1">Company 1</label></td>
<td>2006-07-03T09:40-05:00</td>
<td>user</td>
<td>Some comment</td>
<td>[<a href="javascript:void(0);">edit</a>]</td>
</tr>
<tr>
<td><input type="checkbox" id="2" value="2" /></td>
<td><label for="2">Company 2</label></td>
<td>2006-06-30T14:45-05:00</td>
<td>user</td>
<td>Some comment</td>
<td>[<a href="javascript:void(0);">edit</a>]</td>
</tr>

semi-sentient
10-16-2006, 02:48 PM
Figured it out...

<xsl:for-each select="result/accounts/account">
<xsl:sort select="name" />
<tr>
<td>
<input type="checkbox">
<xsl:attribute name="id"><xsl:value-of select="id" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="id" /></xsl:attribute>
</input>
</td>
<td>
<label>
<xsl:attribute name="for"><xsl:value-of select="id" /></xsl:attribute>
<xsl:value-of select="name" />
</label>
</td>
<td><xsl:value-of select="modDate" /></td>
<td><xsl:value-of select="modBy" /></td>
<td><xsl:value-of select="comments" /></td>
<td>
[<a href="javascript:void(0);"><xsl:attribute name="onclick">javascript:alert('<xsl:value-of select="id"/>');</xsl:attribute>edit</a>]
</td>
</tr>
</xsl:for-each>