Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

xslt input control not setting base on data

I have this data that is being used with this xslt file that I can’t get the Selected true to set the input radio to be checked. Is this the correct logic for checking test="Selected = true" to set that attribute?

Data

<CustomerGender>
      <CustomerGender>
        <Value>802</Value>
        <Text>Female</Text>
        <Selected>false</Selected>
      </CustomerGender>
      <CustomerGender>
        <Value>803</Value>
        <Text>Male</Text>
        <Selected>false</Selected>
      </CustomerGender>
      <CustomerGender>
        <Value>804</Value>
        <Text>Non-binary</Text>
        <Selected>true</Selected>
      </CustomerGender>
      <CustomerGender>
        <Value>805</Value>
        <Text>Prefer not to answer</Text>
        <Selected>false</Selected>
      </CustomerGender>
      <CustomerGender>
        <Value>806</Value>
        <Text>Other (please specify)</Text>
        <Selected>false</Selected>
      </CustomerGender>
    </CustomerGender>

XSLT

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div class="col-md-5">
     <label class="control-label">Gender</label>
     <div class="form-group">
          <div class="radio-list">
               <label>
                    <xsl:for-each select ="Customer/CustomerGender/CustomerGender">
                         <input type="radio" name="selectedGender">
                              <xsl:attribute name="id" >
                                <xsl:value-of select="Value"/>
                              </xsl:attribute>
                              <xsl:attribute name="value">
                                <xsl:value-of select="Value"/>
                              </xsl:attribute>
                              <xsl:if test="Selected = true">
                                <xsl:attribute name="checked">"checked"</xsl:attribute>
                              </xsl:if>
                              <xsl:value-of select="Text"/>
                         </input>
                            &#160;&#160; <br />
                    </xsl:for-each>
               </label>
          </div>
     </div>
</div>

>Solution :

The way your line

<xsl:if test="Selected = true">

works is:

So you probably want to change that into

<xsl:if test="Selected = 'true'">

which will perform a string comparison.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading