Populating a selectbox with selected value???

Discussion in 'XML' started by Si, Jan 30, 2007.

  1. Si

    Si Guest

    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
     
    Si, Jan 30, 2007
    #1
    1. Advertising

  2. Si

    Guest

    On Jan 30, 1:03 pm, "Si" <> wrote:
    > <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>
    </xsl:template>

    > 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.

    --
    Pavel Lepin
     
    , Jan 30, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shankwheat

    Changing Value of a Selectbox

    shankwheat, Jun 22, 2006, in forum: Javascript
    Replies:
    1
    Views:
    83
    Jeremy
    Jun 22, 2006
  2. shankwheat

    Populating a selectbox with a string

    shankwheat, Nov 8, 2006, in forum: Javascript
    Replies:
    0
    Views:
    105
    shankwheat
    Nov 8, 2006
  3. Populating Selectbox

    , Nov 16, 2006, in forum: Javascript
    Replies:
    1
    Views:
    100
  4. shankwheat
    Replies:
    2
    Views:
    141
  5. Michael
    Replies:
    9
    Views:
    82
    Gregor Kofler
    Aug 23, 2008
Loading...

Share This Page