This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Not a nested for loop.
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 16 Jan 2002 14:59:21 -0000
- Subject: RE: [xsl] Not a nested for loop.
- Reply-to: xsl-list at lists dot mulberrytech dot com
> I have a main document,
> form is:
>
> <r id="d0e170156">
> <bibno>079732</bibno>
> <cat-num>10400</cat-num>
> <TBcategory>General fiction</TBcategory>
> <id>079732*RNIB*</id>
> <num-cassettes>1</num-cassettes>
> <play-time>08:47</play-time>
> <rdr-gender>F</rdr-gender>
> <rearch-date/>
> </r>
>
> And an external file, form is:
>
> <bk>
> <n>2</n>
> <t>THE CAR MAKERS</t>
> </bk>
> <bk>
> <n>3</n>
> <t>WYATT'S HURRICANE</t>
> </bk>
> <bk>
> <n>4</n>
> <t>THE RELUCTANT WIDOW</t>
> </bk>
> <bk>
>
>
> I need to loop through each of the main input document
> records (r elements)
> and if r/cat-num is any one of the values of the external file, /bk/n
> then I need to copy the r element and contents through to the output.
>
> Can xslt2.0 help with this form of filtering?
The XSLT 1.0 solution is
<xsl:copy-of select="r[cat-num = document('ext.xml')/bk/n]"/>
and this continues to work in XSLT 2.0.
What XSLT 2.0 (or XPath 2.0) gives you is the ability to extend this to do a
join that isn't a pure equijoin. For example if you want to do a case-blind
comparison you can now write:
<xsl:copy-of select="r[some $c in document('ext.xml')/bk/n
satisfies upper($c)=upper(cat-num)]"/>
Joins other than equijoins weren't in general possible in XPath 1.0, you had
to code them yourself using nested loops at the XSLT level.
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list