Re: [xsl] RE: Modifying a variable while merging 2 XMLs documents !?

Subject: Re: [xsl] RE: Modifying a variable while merging 2 XMLs documents !?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 17 Mar 2006 10:24:37 GMT
> (Because it has eventually been added previously in the for-each loop)

You should not assume that the for loop items are processed in order
they can be processed in any order. It's best to think of them as being
processed in parallel. for-each select="something" just says process
each of the items selected by "something"  (in any order or all at the
same time) The _results_ of the processing are grafted in to the result
tree in a prescribed order, but there is no prescibed ordering on the
order of evaluation, so you can't affect the processing of one item by
the result of processing an "earlier" item.

> So, I still have my original problem : I do not want to copy twice the
> translation if in the glossary the it is doubled. 


> I try your solution, but I get a "Syntax Error" 

You only want to copy if there is not alread an nl entry in the source
so in xpath2 that would be
      
<xsl:copy-of select=" if not(value[@xml:lang='nl'])
 then
document('glossaryNL.xml')/*/*[value[@xml:lang='en']=$value_en][value[@xml:lang='fr']=$value_fr]/value[@xml:lang='nl']
else
()"/>

But as you are using XSLT1 I needed to "fake" the if test in xpath11 (but I made a
mess of the syntax sorry) try

      <xsl:copy-of select="document('glossaryNL.xml')
    [not(current()[value[@xml:lang='nl']])]
/*/*[value[@xml:lang='en']=$value_en][value[@xml:lang='fr']=$value_fr]/value[@xml:lang='nl']"/>

or perhaps more readably do the if in XSLT rather than xpath:

<xsl:if test="not(value[@xml:lang='nl'])">
 <xsl:copy-of select="document('glossaryNL.xml')
   /*/*[value[@xml:lang='en']=$value_en][value[@xml:lang='fr']=$value_fr]/value[@xml:lang='nl']"/>
</xsl:if>

Note that this (in either the xslt2 or xslt1 forms) you need to test a
condition on the _input_ (that it doesn't have an nl) not a condition on
the "result generated so far" (that it has an nl already copied).
That is the essence of functional programming: The result is always
specified as a function of the input.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread