xsl-list
[Top] [All Lists]

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

2011-08-18 15:38:07
On 18 August 2011 20:19,  <dvint(_at_)dvint(_dot_)com> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--