[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Convert String to node-set?

Subject: Re: Convert String to node-set?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 2 May 2002 17:46:51 +0100
convert string to node
Hi Manish,

> What I need to do is iterate through JSPRoot/listing/saleTerms,and
> since it has a and b, i want to set a and b as selected in
> JSPRoot/WizardBluePrint/Property/Category/Group/Field.

It appears to me that what you're trying to do is process the Option
elements within
/JSPRoot/WizardBluePrint/Property/Category/Group/Field, create an
option element for each of them, and add a selected attribute (with
the value 'selected') for those whose value is held higher up in the
data. The location that you check is indicated by the DataLocation and
DatabaseVariableName of the Field that wraps around the particular
Option.

Given that I've interpreted that correctly, I think the easiest
approach is to first index JSPRoot grandchildren by a combination of
their parent's name and their name, as follows:

<xsl:key name="values" match="/JSPRoot/*/*"
         use="concat('/', name(parent::*), '/', name())" />

This means that, for example, you can get the saleTerms elements
within the listing element using:

  key('values', '/listing/saleTerms')

Given that you're on a Field element, then, you can get the second
argument for the call to the key() by concatenating its DataLocation
with the DatabaseVariableName:

<xsl:template match="Field">
  <xsl:variable name="values"
    select="key('values',
                concat(DataLocation, '/', DatabaseVariableName))" />
  ...
</xsl:template>

Then you can iterate over the Option elements within the Field and
create option elements for them, adding the selected attribute if
there value of the Option matches a value in $values:

<xsl:template match="Field">
  <xsl:variable name="values"
    select="key('values',
                concat(DataLocation, '/', DatabaseVariableName))" />
  <xsl:for-each select="Option">
    <option value="{normalize-space(@value)}">
      <xsl:if test=". = $values">
        <xsl:attribute name="selected">selected</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="normalize-space(@value)" />
    </option>
  </xsl:for-each>
</xsl:template>

As far as I can see, there's no need for you to use a node-set()
extension function, or even evaluate(), as long as DataLocation and
DatabaseVariableName only ever contain one element name each.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.