anki
06-28-2005, 10:44 AM
How do I create drop down menu as in HTML using XSLT and use the value of the field selected in drop down menu for other purposes?
Thanks
anki
Thanks
anki
|
Click to See Complete Forum and Search --> : Drop Down menu using XSL anki 06-28-2005, 10:44 AM How do I create drop down menu as in HTML using XSLT and use the value of the field selected in drop down menu for other purposes? Thanks anki jazar 08-24-2005, 09:50 AM Just use <option value="whatever" selected="selected">blahblah</option> Manu ____________ Jazar, you need a bespoke CMS? (http://www.jazar.co.uk/products.html) sheila 08-25-2005, 01:48 PM I use these templates to generate drop-down lists. The values that are going in the list are already defined in the schema for the xml document that I'm processing. So, for example, if I want to create a drop-down list of options for the @status of of something, I use this code to instruct the processor to find the schema (mydoc.xsd) and apply templates to the enumeration values for @status: <select name="status" class="required"> <xsl:apply-templates select="document('mydoc.xsd')//xs:simpleType[@name = 'status']/descendant::xs:enumeration" mode="generate-options"> <xsl:with-param name="selected" select="@status" /> </xsl:apply-templates> </select> If I already have a value that needs to be selected then I pass it in the $status parameter, then if the value of $status is equal to the list option being generated, @selected="selected" gets added to it. <xsl:template match="*" mode="generate-options"> <xsl:param name="selected" /> <xsl:element name="option"> <xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute> <xsl:if test="@value = $selected"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if> <xsl:value-of select="@value" /> </xsl:element> </xsl:template> I also use this template sometimes. It needs to be called by name for each option that you wish to include in your list, and each time you call it you need to pass it three parameters: $value = the value of the option $label = the text representing this option in the list $select = the value of the default/pre-selected option <xsl:template name="option"> <!-- Generates an option to go in the drop-down list --> <xsl:param name="value" /> <xsl:param name="label" /> <xsl:param name="select" /> <xsl:element name="option"> <xsl:attribute name="value"><xsl:value-of select="$value" /></xsl:attribute> <xsl:if test="$value = $select"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if> <xsl:value-of select="$label" /> </xsl:element> </xsl:template> Mirzasb 11-08-2007, 03:55 PM I have my xsl as following. <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="option" type="xs:string" minOccurs="1" maxOccurs="3"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> and corresponding xml. I am trying to generate the drop down using this code. <select name="status" class="required"> <xsl:apply-templates select="document('TimeOptions.xsd')//xs:complexType[@name = 'root']/descendant::xs:sequence" mode="generate-options"> <xsl:with-param name="selected" select="@root" /> </xsl:apply-templates> </select> let me know what is missing. Only blank drop downs are appearing.. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |