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

Subject: Re: [xsl] AVT use and doc() function in xslt 2.0?
From: dvint@xxxxxxxxx
Date: Thu, 18 Aug 2011 14:00:40 -0700
Interesting idea, but I'm not sure I can appli it in the final case. I
actually have multiple levels I need to match. This is what my code looks
like currently:

<xsl:variable name="lookup"

<xsl:copy-of select="$lookup/modelic"/>
<xsl:copy-of select="$lookup/sdc"/>
<xsl:copy-of select="$lookup/chapnum"/>
<xsl:copy-of select="$lookup/section"/>
<xsl:copy-of select="$lookup/subsect"/>
<xsl:copy-of select="$lookup/subject"/>
<xsl:copy-of select="$lookup/discode"/>
<xsl:copy-of select="$lookup/discodev"/>
<xsl:copy-of select="$lookup/incode"/>
<xsl:copy-of select="$lookup/incodev"/>
<xsl:copy-of select="$lookup/itemloc"/>

What I have is one really long key stored in multiple elements and
attributes. Now I control the lookup file format, so I might be able to
concatenate all the values into a single key and then change my template

This is for a conversion effort and ultimatley it should be throwaway
code. I just ran the process on 127 documents/files and it ran pretty fast
with the above. These are s1000d data modules so they are fairly small
doucments to process. The mapping file will be way larger than any of the
individual documents.



> 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

Current Thread