简体   繁体   中英

XSL checkbox display checked if value is 1 from database

How do I read a checkbox value in xsl? I have a value that I read from database and based on this value this checkbox will either be check or unchecked. I have this snipplet but the checkbox does not check even when the database_column value is 1.

<xsl:template.....>
     <form....>
        <input type="checkbox" id="functional_test" name="DATABASE_COLUMN">
           <xsl:if test="//DATABASE_COLUMN='1'">
                <xsl:attribute name="checked">checked</xsl:attribute> 
           </xsl:if>

       </input>
     </form>
</xsl:template>

EDIT: I also have problems retrieving the textarea values. This textarea value is actually from a select option. But when this value is retrieved it's from a database, I have no idea why the value is not appearing. My code looks like this:

 <label class="control-label Mandatory" for="txtRecommendedAction"> Recommended Action*
    <button type="button" class="btn btn-default" href="#modalRecommended" data-toggle="modal"> Retrieve  </button>
 </label>
  <textarea class="form-control" id="txtRecommendedAction" name="recommended_action" rows="6" value="{//RECOMMENDED_ACTION}"/>


It just does not show the correct value in the textarea. Any idea what am I missing?

I know it's weird to answer my own question but after researching the following code did help:

<xsl:element name="input">
          <xsl:attribute name="type">radio</xsl:attribute> <!-- or checkbox -->
          <xsl:attribute name="name">needModeration</xsl:attribute>
          <xsl:attribute name="value">true</xsl:attribute>
          <xsl:if test="contains(needModeration,'true')"> <!-- just change this variable-->
              <xsl:attribute name="checked">
              </xsl:attribute>
          </xsl:if>
</xsl:element>

And in my html, it did check or uncheck based on the values. :D

I got the answer from this forum: http://forums.asp.net/t/1036574.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM