Monday, April 25, 2005

many summers ago (since we dont have winter), i used to write html input type default value in xsl like this:

our simple xml:

<page>
<input_value>hello xm-xsl world</input_value>
</page>

first we declare an xsl variable like so:

<xsl:variable name="input_value">
<xsl:value-of select="page/input_value"/>
</xsl:variable>

then we write our html input like so:

<input type="text" name="text" value="{$input_value}"/>

resulting to a boring html input box with a default value of "hello xml world"...

recently discovered there's another way to do it via . using the sample xml above we can create a similar output with:

<xsl:element name="input">
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="name">text</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="page/input_value"/></xsl:attribute>
</xsl:element>


if page/input_value doesnt exist it simply produces a blank input box. the default value is commonly used when validating a form and you want to retain the user inputted values but wanting to do some fancy label highlighting of the offending fields...

No comments: