Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 22nd, 2004, 01:56 PM
Registered User
 
Join Date: Nov 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default Using xsl to create HTML combo boxes

I am pretty new to this so please bear with me. I have an application that is retrieving xml from another application. I am creating web pages from that xml. What I am trying to do is have the default selected item from a combo box show up in the web page as selected. I have accomplished this but when I select it the return value is incorrect and it selects the wrong option on the original application.

Here is the xml that I get

<Root>
<Row index="0">Administrator</Row>
<Row index="1">John</Row>
<Row index="1">Ray</Row>
<Row index="1" selected="true">Ron</Row>
</Root>

I take the xml and place it in strResultsUser and pass it off to be processed.
strResultsUser = "<widjet><name>Logon</name><type>User</type><values>"+ strResultsUser +"</values></widjet>";

I am processing it through this xsl

 <xsl:if test="name='Logon'">
   <xsl:if test="type='User'">
   <logonid>
  <xsl:for-each select="values/Root/Row[@selected='true']">
    <name selected="true"><xsl:value-of select="."/></name>
  </xsl:for-each>
  <xsl:for-each select="values/Root/Row">
    <name selected="false"><xsl:value-of select="."/></name>
  </xsl:for-each>
  </logonid>
 </xsl:if>
 </xsl:if>

This is my output after I transform it

<logonid xmlns:fo="http://www.w3.org/1999/XSL/Format">
<name selected="true">Ron</name>
<name selected="false">Administrator</name>
<name selected="false">John</name>
<name selected="false">Ray</name>
<name selected="false">Ron</name>
</logonid>

And I present it through this code

<tr><td>User:
 <select size="1" name="cboUser">
<xsl:for-each select="logicresponse/username/logonid/name[@selected= 'true']">
<option selected="true"><xsl:value-of select="."/></option>
</xsl:for-each>
<xsl:for-each select="logicresponse/username/logonid/name[@selected= 'false']">
<option value="{position()-1}"><xsl:value-of select="."/></option>
</xsl:for-each>
</select>
</td></tr>


My issue is when I select the "default selected" item in the combo box
the value it sends back is off. Is there a better way to appraoch this or am I missing something here. I can see that I need to make position 3 the selected but I cannot figure out how.



 
Old November 22nd, 2004, 03:59 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

Do you need to display the Ron choice twice?
<xsl:for-each select="values/Root/Row[@selected='true']">
    <name selected="true"><xsl:value-of select="."/></name>
</xsl:for-each>
<xsl:for-each select="values/Root/Row">
    <name selected="false"><xsl:value-of select="."/></name>
</xsl:for-each>

I suggest changing that to:
<xsl:for-each select="values/Root/Row">
    <name><xsl:copy-of select="@selected/><xsl:value-of select="."/></name>
</xsl:for-each>

just floating an idea. would have to change output code:
<xsl:for-each select="logicresponse/username/logonid/name">
<option value="{position()-1}">
<xsl:if test="@selected='true'><xsl:copy-of select="@selected"/></xsl:if><xsl:value-of select="."/></option>
</xsl:for-each>
 
Old November 22nd, 2004, 05:02 PM
Registered User
 
Join Date: Nov 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default

nope, I do not need the name ron twice. I followed your suggestion and it worked nicely. One question

This was my output

<option value="0">Administrator</option>
<option value="1">John</option>
<option value="2">Ray</option>
<option value="3" selected="true">Ron</option>


This was the code you suggested

<option value="{position()-1}">
<xsl:if test="@selected='true'><xsl:copy-of select="@selected"/></xsl:if><xsl:value-of select="."/></option>

My question is by testing for that attribute does xsl add that as an attribute when true to the option element? It seems to do that, I just want to see if what I am thinking is actually the case.

Thanks
Ron

 
Old November 22nd, 2004, 06:42 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

yes, that's exactly what it does.

 
Old November 23rd, 2004, 05:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

And if you're trying to output HTML then the selected attribute should have a value of "selected", not true.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Boxes nbuckwheat Access 1 January 15th, 2006 09:26 AM
regarding combo boxes using html and javascript preethi.c Beginning VB 6 5 March 3rd, 2005 06:36 AM
How to create a tables with combo boxes in MS Word ozzie-boof VB How-To 0 March 14th, 2004 11:55 PM
combo boxes damnnono_86 Access 2 October 15th, 2003 09:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.