Jump to content

complex attributes


dooberry
 Share

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.

<xdata><item1>400</item1></xdata>

is in the data file.in the list we have

<xlistitems><listitem>100</listitem><listitem>200</listitem><listitem>300</listitem><listitem>400</listitem></xlistitems>

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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...