User Tools

Site Tools


notes:xslt:html_controls

HTML Controls in XSLT

Below, there are a few examples of generating HTML controls using XSLT:

CheckBox:

<xsl:call-template name="checkBox">
    <xsl:with-param name="id" select="'chkStatus'"/>
    <xsl:with-param name="val" select="'open'"/>
</xsl:call-template>       
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
 
<xsl:template name="checkBox">
    <xsl:param name="id"/>
    <xsl:param name="val"/>
    <input type="checkbox"> 
        <xsl:if test="$val != ''">
            <xsl:attribute name="checked"><xsl:value-of select="'checked'"/></xsl:attribute>
        </xsl:if>
        <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
        <xsl:attribute name="value"><xsl:value-of select="$val"/></xsl:attribute>
        <xsl:value-of select="$val"/>
    </input>
</xsl:template>

DropDownList:

<xsl:call-template name="optionItem">
    <xsl:with-param name="val" select="'sortByName'"/>
    <xsl:with-param name="txt" select="'By Name (ascending)'"/>
</xsl:call-template>       
 
<xsl:template name="optionItem">
    <xsl:param name="val"/>
    <xsl:param name="txt"/>
    <option>
        <xsl:if test="/request/args/sort = $val">
            <xsl:attribute name="selected"><xsl:value-of select="'selected'"/></xsl:attribute>
        </xsl:if>
        <xsl:attribute name="value"><xsl:value-of select="$val"/></xsl:attribute>
        <xsl:value-of select="$txt"/>
    </option>
</xsl:template>

TextArea:

<xsl:call-template name="textArea">
    <xsl:with-param name="id" select="'txtComment'"/>
</xsl:call-template>   
 
<xsl:template name="textArea">
    <xsl:param name="id"/>
    <textarea rows="1" cols="55" wrap="soft" style="overflow:hidden" 
              onfocus="this.rows=10;this.style.overflow='scroll';" 
              onblur="this.rows=1;this.style.overflow='hidden';">
        <xsl:attribute name="onkeyup">
            <xsl:text>document.getElementById('</xsl:text> 
            <xsl:value-of select="$id"/>
            <xsl:text>').value=this.value</xsl:text>
        </xsl:attribute>
    </textarea>
</xsl:template>
notes/xslt/html_controls.txt · Last modified: 2017/05/02 by leszek