[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Dropdown

Subject: RE: Dropdown
From: Juan Carlos Gonzalez <jcgonz@xxxxxxxxx>
Date: Tue, 22 Oct 2002 12:39:54 -0700 (PDT)
xsl dropdown
This is how the XML file looks:

<root>
 <csd CatId="1">
   <sd DetailId="112" Name="Warranty" Val="1 Year"
Type="CheckBox" /> 
  <sd DetailId="113" Name="Warranty" Val="2 Years"
Type="CheckBox" /> 
  <sd DetailId="110" Name="Type" Val="Leather"
Type="Radio" /> 
  <sd DetailId="111" Name="Type" Val="Plastic"
Type="Radio" /> 
  </csd>
 <csd CatId="38">
  <sd DetailId="108" Name="Size" Val="AA" Type="Radio"
/> 
  <sd DetailId="109" Name="Size" Val="AAA"
Type="Radio" /> 
  </csd>
 <csd CatId="369">
  <sd DetailId="119" Name="Color" Val="Black"
Type="DropDown" /> 
  <sd DetailId="120" Name="Color" Val="Blue"
Type="DropDown" /> 
  <sd DetailId="121" Name="Color" Val="Red"
Type="DropDown" /> 
 </csd>
</root>

Is there a way to change the select tag from <select>
to &lt;select&gt; so the parser won't give me an
error?

Thanks.


--- "Passin, Tom" <tpassin@xxxxxxxxxxxx> wrote:
> [Juan Carlos Gonzalez]
> > 
> > This is my template. I'm trying to generate input
> tags
> > based on the type read from the xml file.
> > 
> 
> Just guessing at the xml file you want to transform,
> I do not think that
> your stylesheet would quite do what you want even if
> you could have
> gotten away with the ill-formed construction.  Of
> course, I do not know
> whether all the options would be listed in order
> with no other  inputs
> mixed in.
> 
> I take it that you will have a list of elements
> whose Type attribute is
> "dropdown", whose name is to be the name of the
> select element, and
> whose Val atribute is to become the value of an
> option.  There should be
> just one select element for such a group of options,
> and you want to
> output it when you encounter the first element with
> a new name.  Right?
> 
> It would be better if you could change your xml
> format to have all the
> options contained in a container element.  Then
> things would be easier.
> Then, for each container you would create a select
> element.  Can you do
> change the format?
> 
> Otherwise, you could proceed like this (a brute
> force approach that
> makes minimal changes to what you already had) -
> depending, of course,
> on what is really in the xml file:
> 
> > 
> > <xsl:template match="csd">
> >   <xsl:for-each select="sd[count(. |
> key('specs_key', @Name)[1])=1]">
> >   <xsl:if test="@Type = 'DropDown'"> 
> >     <select name="Name">
> >      <option value="-">--Select Name--</option>
>              <xsl:for-each select="key('specs_key',
> @Name)[@Type =
> 'DropDown']">
>  	    <option value='{@Val}'><xsl:value-of
> select="@Val"/></option>
> 	</xsl:for-each>
>       </select>
> >   </xsl:if> 
> 
> >   <xsl:for-each select="key('specs_key',
> @Name)[not(@Type
> ='DropDown')]">
> >     <xsl:choose>
> > 	<xsl:when test="@Type = 'DropDown'"> 
> > 	</xsl:when>
> > 	<xsl:when test="@Type = 'CheckBox'"> 
> > 	   <xsl:element name="input">
> > 	<xsl:attribute
> name="type">checkbox</xsl:attribute>
> > 	<xsl:attribute name="id"><xsl:value-of 
> > select="@DetailId"/></xsl:attribute>
> > 	</xsl:element>
> > 	</xsl:when>
> > 	<xsl:when test="@Type = 'Radio'"> 
> > 	<xsl:element name="input">
> > 	<xsl:attribute name="type">radio</xsl:attribute>
> > 	<xsl:attribute name="id"><xsl:value-of 
> > select="@DetailId"/></xsl:attribute>
> > 	<xsl:value-of select="@Val"/>?
> > 	</xsl:element>
> > 	</xsl:when>
> > 	<xsl:when test="@Type = 'Free Form Text'"> 
> > 	<xsl:value-of select="@Val"/>
> > 	</xsl:when>
> >       </xsl:choose>
> >    </xsl:for-each>
> > </xsl:for-each>
> > </xsl:template>
> > 
> > 
> > 
> > --- "Passin, Tom" <tpassin@xxxxxxxxxxxx> wrote:
> > > [ Juan Carlos Gonzalez]
> > > > 
> > > > I'm trying to create a drop down list box
> > > dynamically,
> > > > but I'm getting an error message cause the
> > > "select"
> > > > tag is not being closed within the "if" tag. I
> > > have
> > > > tried replacing the < and > sign with the &lt;
> and
> > > > &gt; but it's still not working. Any ideas?
> > > > 
> > > > <xsl:if test="some condition">
> > > >   <select name="cat">
> > > > </xsl:if>
> > > > 
> > > > ...the folowing template will create the
> options
> > > tag
> > > > amoung other things ...
> > > > 
> > > > <xsl:apply-templates select="cat"/>
> > > > 
> > > > <xsl:if test="some condition">
> > > >   </select>
> > > > </xsl:if>
> > > 
> > > You must complete and close the select element
> > > within the xsl:if
> > > element. Remember that the stylesheet has to be
> > > well-formed xml.   If
> > > you think that you need to do something else,
> you
> > > have not understood
> > > your problem thoroughly enough yet.  If you
> explain
> > > what you really wish
> > > to accomplish, we will be able to help you with
> it.
> > > 
> > > For example, if you want to create a select
> element,
> > > then you surely
> > > will want to create options inside it.  If you
> want
> > > to create the select
> > > list only if there are any cat elements, and
> have
> > > one option per cat,
> > > then you could write (assuming that the "cat"
> > > element contains the name
> > > of the cat as character data)
> > > 
> > > <xsl:if test='cat'> <!-- executed if there are
> any
> > > "cat" child elements
> > > -->
> > > 	<select name='cat'>
> > > 		<xsl:for-each select='cat'>
> > > 			<option value='{.}'><xsl:value-of
> > > select='.'/></option>
> > > 		</xsl:for-each>
> > > 	</select>
> > > </xsl:if>
> > > 
> > > If you specify an xsl:output method of 'html',
> the
> > > output will be in
> > > ordinary html (rather than in xml), and the
> options
> > > will come out
> > > looking like normal html options:
> > > 
> > > <option value='Mary'>Mary
> > > 
> > > You could also use apply-templates instead of
> the
> > > for-each, which might
> > > be better if you have more complex processing to
> do
> > > in constructing the
> > > options.  In this case, you would build the
> options
> > > in the template for
> > > "cat" rather than as shown here.
> > > 
> > > Cheers,
> > > 
> > > Tom P
> > > 
> > >  XSL-List info and archive:
> > > http://www.mulberrytech.com/xsl/xsl-list
> > > 
> > 
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > Y! Web Hosting - Let the expert host your web site
> > http://webhosting.yahoo.com/
> > 
> >  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> > 
> > 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.