|
Subject: Re: [xsl] 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 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] AVT use and doc() functio, dvint | Thread | Re: [xsl] AVT use and doc() functio, dvint |
| Re: [xsl] AVT use and doc() functio, dvint | Date | Re: [xsl] AVT use and doc() functio, dvint |
| Month |