Re: Option in form problem

Subject: Re: Option in form problem
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 08 May 2000 11:57:01 -0400
At 00/05/08 11:12 -0400, Elder, Larry wrote:
I'm trying to create a blank line in a drop down list. The list is inside a
form, obviously.

What I'm using, and works BTW, is...

<xsl:element name="OPTION">
  <xsl:attribute name="SELECTED"/>

The output I get is

<Option selected="" />

Correct, because you haven't supplied a value for the attribute.

You can use a literal result element:

<OPTION selected="selected"/>

... or instructions:

<xsl:element name="OPTION">
  <xsl:attribute name="selected">selected</xsl:selected>

What I want is the more robust...

<Option selected />

Actually, "robust" isn't the word to use here ... SGML markup minimization allows the name of the attribute to be omitted when the available tokens are unique. If you looked at the SGML Document Type Definition for HTML you would find:

        selected (selected) #IMPLIED
        value  CDATA  #IMPLIED -- defaults to element content --

The SGML way of specifying this without using minimization is:

<OPTION selected="selected"></OPTION>

This need is recognized by XSLT processors recognizing the HTML output method, thus those processors will suppress the attribute name.

I hope my example below helps (the use of the HTML document element may screw up some mail readers, such as my Eudora 4).

.............. Ken

T:\ftemp>type test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:template match="/">                         <!--root rule-->
     <OPTION selected="selected"/>
     <xsl:element name="OPTION">
       <xsl:attribute name="selected">selected</xsl:attribute>


T:\ftemp>xt test.xsl test.xsl
<test1><OPTION selected></OPTION></test1><test2><OPTION selected></OPTION></test


G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.   
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-04-7
Next instructor-led training:               2000-05-11/12,2000-05-15,
-                                    2000-06-12,2000-06-13,2001-01-27

XSL-List info and archive:

Current Thread