[Top] [All Lists]

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

2011-08-18 16:00:52
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(_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:


I will find the info in the secondary file that I'm looking for.

If I do this, no result is returned:


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')

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

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: 

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>