This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Convert String to node-set?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]