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

RE: work-around for poor XML design needed

Subject: RE: work-around for poor XML design needed
From: "Dion Houston" <dionh@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 23 Oct 2002 12:08:23 -0700
xml country list
Hi John:

The way I'd attack this is by creating a key on the country which
contains the preceding region's country element as the value:

<xsl:key name="parent-region" match="/states/country"
use="preceding-sibling::region[1]/country"/>

This then will give you the associated region for any given region.

I'd then write a template that matches on region, and to display the
list apply templates on those elements with the current region as it's
parent perhaps with a different mode i.e.

<xsl:template match="region">
   ...
   <xsl:apply-templates select="key('parent-region', country)"
mode="processChildren"/>
</xsl:template>

And then in your root template simply do your separate processing for
those countries with no region.

HTH!

Dion

-----Original Message-----
From: jdunning [mailto:jdunning@xxxxxxxxx] 
Sent: Wednesday, October 23, 2002 9:57 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  work-around for poor XML design needed

Hi all,
I need a workaround for a poor XML design.  The XML structure is as
follows:
<states>
<!-- countries which belong to no regional organization -->
  <country>AA</country>
  <country>AB</country>
  <country>AC</country>
  <country>AD</country>
<!-- a regional organization -->
  <region>
      <!-- the name of the regional org. is a country code -->
       <country>AP</country>
  </region>
<!-- countries following a region are members of that regional org. -->
  <country>GH</country>
  <country>GM</country>
  <country>KE</country>
  <country>UG</country>
<!-- another regional org. -->
  <region>
      <!-- the other regional org.'s name -->
       <country>EP</country>
  </region>
<!-- members of that regional org. -->
  <country>AT</country>
  <country>BE</country>
  <country>CH</country>
  <country>LI</country>
  <country>CY</country>
</states>

What I need is to display a list of regional organizations with members,
followed by all countries not in an organization as such:

AP: (GH, GM, KE, UG); EP: (AT, BE, CH, LI, CY); AA, AB, AC, AD

The problem is that the countries that make up a region are not
elementally
contained and I'm unsure of a way to specify "the <country> elements
between
this <region> and the next <region>"

This is the template I've been working with:

<xsl:for-each select="states/region/country">
    <xsl:value-of select="."/>:(
    <!-- PROBLEM: all following countries are siblings (regardless of
               which region they should belong to -->
             <xsl:for-each
select="parent::region/following-sibling::country">
                 <xsl:value-of select="."/>
                 <xsl:if test="not(position()=last)">
                    <xsl:text> </xsl:text>
                </xsl:if>
             </xsl:for-each>);
   </xsl:for-each>
     <xsl:if test="parent::region[1]/preceding-sibling::country">
           <xsl:for-each
select="parent::region[1]/preceding-sibling::country">
                <xsl:value-of select="."/>
                <xsl:if test="not(position()=last)">
                    <xsl:text> </xsl:text>
                </xsl:if>
           </xsl:for-each>
      </xsl:if>

Any help is always appreciated.  TIA, John


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


 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.