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

Re: Dynamic output dependant on existance of other nod

Subject: Re: Dynamic output dependant on existance of other nodes.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 8 Nov 2001 15:39:35 +0000
select xsl
Hi Ian,

> If Airport_choices exists, and Airport exists, then the menu is
> populated by the contents of Airport_choices and the formfield Name
> attribute is set to "Airport".
>
> If Airport_choices exists, and Airport does not exist, simply
> display a list populated by the contents of Airport Choices and the
> formfield Name attribute is set to "Airport_choices".

In a template matching the Item element, you can work out whether this
Item is an Airport_choices Item with:

  @Name = 'Airport_choices'

You can find the sibling Item elements with:

  ../Item

and you can work out whether one of them has a Name attribute equal to
'Airport' with:

  ../Item/@Name = 'Airport'

So in the template for Item elements:

  <xsl:choose>
    <xsl:when test="@Name = 'Airport_choices'">
      <xsl:variable name="fieldname">
        <xsl:choose>
          <xsl:when test="../Item/@Name = 'Airport'">Airport</xsl:when>
          <xsl:otherwise>Airport_choices</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <select name="{$fieldname}">
        <xsl:for-each select="Val">
          <option><xsl:value-of select="." /></option>
        </xsl:for-each>
      </select>
    </xsl:when>
    <xsl:otherwise>...</xsl:otherwise>
  </xsl:choose>

> This needs to work for combinations of any <itemname>_choice and
> <itemname> pair.

You can test whether this Item has a name in the form
<itemname>_choices with:

  substring-after(@Name, '_') = 'choices'

You can find the itemname from the name of the current Item with:

  substring-before(@Name, '_choices')

Inserting this into the above code, you get:

  <xsl:choose>
    <xsl:when test="substring-after(@Name, '_') = 'choices'">
      <xsl:variable name="itemname"
                    select="substring-before(@Name, '_choices')" />
      <xsl:variable name="fieldname">
        <xsl:choose>
          <xsl:when test="../Item/@Name = $itemname">
            <xsl:value-of select="$itemname" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@Name" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <select name="{$fieldname}">
        <xsl:for-each select="Val">
          <option><xsl:value-of select="." /></option>
        </xsl:for-each>
      </select>
    </xsl:when>
    <xsl:otherwise>...</xsl:otherwise>
  </xsl:choose>


I hope that helps,

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-2013 All Rights Reserved.