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

Fw: changing scope in for-each

Subject: Fw: changing scope in for-each
From: "jdunning" <jdunning@xxxxxxxxx>
Date: Wed, 26 Jun 2002 17:34:16 +0200
xsl for each scope
Hi all,
I'm wondering how to change the scope back to the XML document when in a
for-each loop using the document('') function for creating a lookup table.
What I'm trying to do is compare a list of states in the XML document to the
lookup table, and if one is present in the lookup table but not the
document, place "except (state)" in the rendered output.  Once I start
looping through the lookup table my XPath expressions against the XML
document fail, presumably because the scope has now shifted to the
stylesheet.
Thanks in advance for any ideas, suggestions, education.
John

My XML is :
   <regional>
    <region>
     <country>AP</country>
    </region>
   <!-- note country 'GH' missing -->
    <country>GM</country>
    <country>KE</country>
    <country>LS</country>
    <country>MW</country>
    <country>MZ</country>
    <country>SD</country>
    <country>SL</country>
    <country>SZ</country>
    <country>TZ</country>
    <country>UG</country>
    <country>ZM</country>
    <country>ZW</country>
   </regional>

My lookup table (contained in the stylesheet) is:
<LU:organizations>
 <LU:organization name="AP">
  <LU:state name="GH"/>
  <LU:state name="GM"/>
  <LU:state name="KE"/>
  <LU:state name="LS"/>
  <LU:state name="MW"/>
  <LU:state name="MZ"/>
  <LU:state name="SD"/>
  <LU:state name="SL"/>
  <LU:state name="SZ"/>
  <LU:state name="TZ"/>
  <LU:state name="UG"/>
  <LU:state name="ZM"/>
  <LU:state name="ZW"/>
 </LU:organization>
</LU:organizations>

And my XSL is (currently):
        <xsl:for-each select=".//regional">
         <xsl:sort select="."></xsl:sort>
            <xsl:value-of select="./region/country"></xsl:value-of>
            <xsl:variable name="contractingCountry"
select="translate(./region/country,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJK
LMNOPQRSTUVWXYZ')"></xsl:variable>
            <xsl:text>: </xsl:text>

      <xsl:variable name="lookup" select="document('')"/>
      <xsl:variable name="cc" select="."/><!-- country code in XML doc-->
     <!-- this changes the scope from the XML document to the stylesheet -->
      <xsl:for-each
select="$lookup//LU:organization[@name=$contractingCountry]/LU:state">
         <!-- now the XPath //region/country is not in scope, so expression
fails -->
       <xsl:if
test="not(@name=//region/country[text()=$contractingCountry]/following-sibli
ng::country)">
            (except <xsl:value-of select="@name"/>)   <!-- should return
"(except GH)" -->
       </xsl:if>
      </xsl:for-each>
</xsl:for-each>


 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.