Jump to content

complex attributes

Recommended Posts

I want to set a value for an attribute that isn't stored in the xml file.What I have is an xml file with some data in it.I am then populating a Select control with data from another XML file.I want the Select control to show the item which corresponds to the value in the data store using the "selected" attribute of the select control.e.g.


is in the data file.in the list we have


To create the dropdown I have code which says:

<select><xsl:for-each select="document('listitems')//xlistitems/listitem"><option><xsl:attribute name="value"><xsl:value-of select="listitem"></xsl:attribute></option></xsl:for-each></select>

What I want to do is add the selected attribute if the value of listitem matches the value in xdata/item1.Firstly, is this explained ok and secondly can anyone help please??? :) :)Dooberry

Link to post
Share on other sites

I cracked it!!!I used a variable to get the data that had been entered.Then I used xsl:if to compare this to the list item.Within xsl:if I defined the selected attribute as the current list item.Here is the code:

<select id="selectcontrol"><xsl:for-each select="document('xlist.xml')//xlistitems/listitem" ><xsl:variable name="entereditem"  select="document('xdata.xml')//xdata/item1" /><option><xsl:attribute name="value" >   <xsl:value-of select="listitem" /></xsl:attribute><xsl:if test="listitem=$entereditem"><xsl:attribute name="selected">  <xsl:value-of select="'selected'" /></xsl:attribute></xsl:if></option></xsl:for-each></select>

Here endeth the lesson!!Dooberry :)

To infinity ... and beyond!!!!!
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...