This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Option in form problem


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"/>
>   </xsl:element>
>
>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>
</xsl:element>

>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:

<!ELEMENT OPTION - O (#PCDATA)*>
<!ATTLIST OPTION
         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="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

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

</xsl:stylesheet>


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

T:\ftemp>

--
G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
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:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]