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

Re: AVT use and doc() function in xslt 2.0?

Subject: Re: AVT use and doc() function in xslt 2.0?
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 18 Aug 2011 21:37:57 +0100
Re:  AVT use and doc() function in xslt 2.0?
On 18 August 2011 20:19,  <dvint@xxxxxxxxx> wrote:
> I'm writing a stylesheet to process an xml file based upon data in a
> second file. Actually I'm trying to map values in the source file being
> processed against the lookup and then new values in the secondary file
> being read with the doc() function.
>
> So if I do this:
>
> <xsl:copy-of
> select="doc('dmcmapping.xml')/searchReplace/smodelic[@val='GAASIB0']"/>
>
> I will find the info in the secondary file that I'm looking for.
>
> If I do this, no result is returned:
>
> <xsl:copy-of
> select="doc('dmcmapping.xml')/searchReplace/smodelic[@val='{modelic}']"/>
>
> where modelic is an elemnt I'm matching in the source document.

The context within the predicate [ ] there is the <smodelic> element,
so to refer to the context node outside of the xpath you can use
current() eg [@val = current()/modelic]  (plus you don't use avts
within select attributes)

However the nice way to do lookups like this is to use the 3rd
argument of the key function:

1 - define a variable holding the lookup xml:

<xsl:variable name="dmc-mapping-doc" select="doc('dmcmapping.xml')
as="document-node(searchReplace)"/>

2 - define a key to return the element <smodelic> based on its @val

<xsl:key name="smodelic-by-val" match="smodelic" use="@val"/>

3 - use the key to do lookups:

<xsl:copy-of select="key('smodelic-by-val', modelic, $dmc-mapping-doc)"/>



-- 
Andrew Welch
http://andrewjwelch.com

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.