Subject: [xsl] Fw: changing scope in for-each From: "jdunning" <jdunning@xxxxxxxxx> Date: Wed, 26 Jun 2002 17:34:16 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT Explanatory Referenc, B. Tommie Usdin | Thread | Re: [xsl] Fw: changing scope in for, David Carlisle |
Re: [xsl] XSLT Explanatory Referenc, Vasu Chakkera | Date | RE: [xsl] merging generic elements , Américo Albuquerque |
Month |