xsl-list
[Top] [All Lists]

RE: Re: xsl and checkbox

2002-10-09 13:38:21
Here are sample xml, xsl, and html files:
#####################################
<?xml version="1.0"?>
<root>
  <item id="1" checked="true">fruits</item>
  <item id="2" checked="false">cereals</item>
  <item id="3" checked="false">legumes</item>
  <item id="4" checked="true">tubers</item>
</root>
######################################
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
  <xsl:output method="html" indent="yes" encoding="UTF-8" />
  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>
  <xsl:template match="root/item">
    <xsl:element name="input">
      <xsl:if test="@checked='true'">
        <xsl:attribute name="checked">true</xsl:attribute>
      </xsl:if>
      <xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
      <xsl:attribute name="type">checkbox</xsl:attribute>
      <xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>
######################################
  <input checked="true" id="1" type="checkbox" value="fruits">fruits</input>
  <input id="2" type="checkbox" value="cereals">cereals</input>
  <input id="3" type="checkbox" value="legumes">legumes</input>
  <input checked="true" id="4" type="checkbox" value="tubers">tubers</input>
######################################

You could use JavaScript to inspect the "checked" attribute by using this DOM 
programming technique:

if(document.getElementById("1").checked){
 ... whatever you need to do here
}

Is this clear, or does it require further explanation?
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     "Frans Herbst" <fherbst(_at_)cortell(_dot_)co(_dot_)za>
Sent:     Wed, 9 Oct 2002 21:33:12 +0200
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  Re: [xsl] xsl and checkbox

When you say "reference it with javascript", do you mean you want to
inspect it after it is loaded on the browser, or during the transformation
to HTML?

Well the easiest possible, I need to populate a string with all the selected
items when I submit the page.
If I could check anytime if the checkbox is selected I could populate a
hidden list box with the info, but everthing I have tried results to an
unidentifier to the listbox or attribute I defined for the listbox.

Any help on this would be very much appreciated.

 Frans Herbst



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>