Subject: RE: [xsl] Selecting an option From: Heather Lindsay <heather.lindsay@xxxxxxxxxxxxx> Date: Wed, 12 Sep 2001 15:37:56 -0400 |
hi, I'm not sure if this is what you are asking without more information but here it goes... Say you have an XML file that looks like this: <myFile> <myValues> <value>1</value> <value>2</value> <value>3</value> <value>4</value> <value>5</value> </myValues> <defaultValue>5</defaultValue> </myFile> And you want an html like this: <HTML> <Body> <Table> <tr> <td> <select name="myMenu"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5" selected="selected">5</option> </select> </td> </tr> </Table> </Body> </HTML> Then you would need this XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table> <tr> <td> <select name="myMenu"> <xsl:apply-templates select="myFile/myValues/value"> <xsl:with-param name="default" select="myFile/defaultValue"/> </xsl:apply-templates> </select> </td> </tr> </table> </body> </html> </xsl:template> <xsl:template match="value"> <xsl:param name="default"/> <xsl:choose> <xsl:when test=". = $default"> <option value="{.}" selected="selected"><xsl:value-of select="."/></option> </xsl:when> <xsl:otherwise> <option value="{.}"><xsl:value-of select="."/></option> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> I hope that helps. It's hard to know what you are asking for without example XML and the relevant segment of what you've tried so far in your XSLT. Good luck, Heather -----Original Message----- From: Carlos Durand Silvestrin [mailto:csilvestrin@xxxxxxxxxxx] Sent: Wednesday, September 12, 2001 1:53 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Selecting an option I want to know the better way to select one option below using XSLT: <select name="note"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> </select> For example, select the 5th option when my node in XML has the same value <option value="5" selected="selected">5</option> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Sorting Problem, Michael Kay | Thread | RES: [xsl] Selecting an option, Carlos Durand Silves |
Re: [xsl] Sorting Problem, Jörg Heinicke | Date | RE: [xsl] Fast Processor XSLt, Michael Kay |
Month |