Populating a selectbox with selected value???

S

Si

I'm going round in circles trying to set a value as selected in a
dropdown box on an ASP page.
Basically this is the XML I've got:

<rs:data>
<z:row DirectorateID="67" DirectorateName="CEO"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="68" DirectorateName="eIS"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="69" DirectorateName="S&C"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="70" DirectorateName="F&CR"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="71" DirectorateName="O&S"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="73" DirectorateName="HR"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="74" DirectorateName="SM&C"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="75" DirectorateName="F&CS"
rsName="rc_listDirectorates_sp" />
</rs:data>
-<rs:data>
<z:row AuthorID="11" FullName="Jo West" FirstName="Jo"
LastName="West" DateCreated="2006-12-11" theDirectorateID="74"
rsName="rc_listUsers_sp" />
</rs:data>

The top <rs:data> populating the dropdown box and it's 'selected'
value being determined by the DirectorateID in the next <rs:data>

At the minute I'm think ing of XSLT something like:

<xsl:template match="rs:data[z:row/
@rsName='rc_listDirectorates_sp']">
Directorate:
<select name="Directorates">
<xsl:apply-templates />
</select>
</xsl:template>

<xsl:template match="rs:data/
z:row[@rsName='rc_listDirectorates_sp']">
<xsl:choose>
<xsl:when test="@DirectorateID !=
@DirectorateID">
<option
value="{@DirectorateID}">
<xsl:value-of
select="@DirectorateName"/>
</option>
</xsl:when>
<xsl:eek:therwise>
<option selected="selected"
value="{@DirectorateID}">
<xsl:value-of
select="@DirectorateName"/>
</option>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

but is this any good? Is this even possible?!?

Sorry if this is a stupid question but I'm a DBA by trade.

Thanks
 
P

p.lepin

<rs:data>
<z:row DirectorateID="67" DirectorateName="CEO"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="68" DirectorateName="eIS"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="69" DirectorateName="S&C"

Not well-formed.
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="70" DirectorateName="F&CR"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="71" DirectorateName="O&S"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="73" DirectorateName="HR"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="74" DirectorateName="SM&C"
rsName="rc_listDirectorates_sp" />
<z:row DirectorateID="75" DirectorateName="F&CS"
rsName="rc_listDirectorates_sp" />
</rs:data>
-<rs:data>

You seem to have forgotten something in there.
<z:row AuthorID="11" FullName="Jo West" FirstName="Jo"
LastName="West" DateCreated="2006-12-11"
theDirectorateID="74" rsName="rc_listUsers_sp" />
</rs:data>

The top <rs:data> populating the dropdown box and it's
'selected' value being determined by the DirectorateID in
the next <rs:data>

[...]
<xsl:when test="@DirectorateID != @DirectorateID">

Here's your problem. Precisely when do you expect this
condition to be true? You're comparing a value to itself,
so of course this will always be false. (As a matter of
fact, I remember a copy protection system for floppy disks
from the 80s that was doing exactly that and expecting true
as a proof that the floppy disk contained a legitimate copy
of the software. AFAIR, the catch was that you could have
two sectors with the same number--but different contents--
on a track, so with proper timing you could read the
seemingly same sector twice and get different results.)

Anyway, what you really need is current(). Read a little
about it, and it should be immediately obvious how to solve
your problem.
but is this any good?

Does it work? (No, it doesn't, but you should've told us
that. And it would be nice to mention what exactly doesn't
seem to work.)
Is this even possible?!?

Certainly. The following works on my test document:

<xsl:template
match=
"
rs:data[z:row/@rsName='rc_listDirectorates_sp']
">
<xsl:text>Directorate: </xsl:text>
<select>
<xsl:apply-templates/>
</select>
</xsl:template>
<xsl:template
match=
"
rs:data/z:row[@rsName='rc_listDirectorates_sp']
">
<option>
<xsl:attribute name="value">
<xsl:apply-templates select="@DirectorateID"/>
</xsl:attribute>
<xsl:apply-templates
select=
"
../../rs:data/z:row
[@rsName='rc_listUsers_sp']
[@theDirectorateID=current()/@DirectorateID]
" mode="selected"/>
<xsl:apply-templates select="@DirectorateName"/>
</option>
</xsl:template>
<xsl:template
match=
"
rs:data/z:row
[@rsName='rc_listUsers_sp']
[@theDirectorateID]
" mode="selected">
<xsl:attribute name="selected">selected</xsl:attribute>
said:
Sorry if this is a stupid question but I'm a DBA by
trade.

Not at all a stupid question, but you should've checked
what you are posting to the USENET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top