Jump to content

Non file entries in XSL file


ameliabob

Recommended Posts

I am trying to put checkboxes in a table and to have them checked or not depending on a field in the XML fileThe code that I am using is:

                             	<xsl:if test="used == 'true'" >                                	<input type="checkbox" checked=true name="able" value="yes"  />                                <otherwise>                             		<input type="checkbox" name="able" value="yes"  />                                </otherwise>                                    </xsl:if>    

The field that I am testing is "used" and its value will either be "true" or "false" (the words). As you may imagine I am getting nasty diagnostics coming back.

Link to comment
Share on other sites

Also note that you're using <otherwise>, when you should be using <xsl:otherwise> and in a choose instead, like so:

	<xsl:choose>		<xsl:when test="used = 'true'">			<input type="checkbox" checked="true" name="able" value="yes"  />		</xsl:when>		<xsl:otherwise>			<input type="checkbox" name="able" value="yes"  />		</xsl:otherwise>	</xsl:choose>

In addition, I notice that the only difference in your case in the checked attribute. Because of that, I'd suggest you use xsl:attribute conditionally instead:

	<input type="checkbox" name="able" value="yes">		<xsl:if test="used = 'true'">			<xsl:attribute name="checked">checked</xsl:attribute>		</xsl:if>	</input>

Link to comment
Share on other sites

  • 3 weeks later...
Also note that you're using <otherwise>, when you should be using <xsl:otherwise> and in a choose instead, like so:
	<xsl:choose>		<xsl:when test="used = 'true'">			<input type="checkbox" checked="true" name="able" value="yes"  />		</xsl:when>		<xsl:otherwise>			<input type="checkbox" name="able" value="yes"  />		</xsl:otherwise>	</xsl:choose>

In addition, I notice that the only difference in your case in the checked attribute. Because of that, I'd suggest you use xsl:attribute conditionally instead:

	<input type="checkbox" name="able" value="yes">		<xsl:if test="used = 'true'">			<xsl:attribute name="checked">checked</xsl:attribute>		</xsl:if>	</input>

Would the attribute transfer as showing the checkmark in the checkbox?
Link to comment
Share on other sites

  • 2 weeks later...
Would the attribute transfer as showing the checkmark in the checkbox?
Um... yes?What XSLT in general does is to generate another XML or (X)HMTL code and that code is then parsed. Try to do the same in a plain XHTML document, and if it happens there, it will happen when in XSLT as well.As far as I know,
	<input type="checkbox" name="able" value="yes" checked="checked" />

is indeed a valid XHTML that shows a checked checkbox.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...