xsl-list
[Top] [All Lists]

[xsl] Problem with Key matching XSLT 1.0

2010-09-14 05:18:22
Dear List

I am trying to compare two xml documents of the same format.  I have
successfully transformed the documents to include a field called ItemKey
which includes a unique key (comprised of four other elements).  I am
now trying to match and compare elements based on that key value.

My XSLT includes the following as "global" variables:

<xsl:variable name="file1">test_comp4.xml</xsl:variable>
<xsl:variable name="old_file"
select="document($file1)/*"></xsl:variable>
<xsl:variable name="file2">test_comp4_edited.xml</xsl:variable>
<xsl:variable name="new_file"
select="document($file2)/*"></xsl:variable>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="test" match="//ItemKey" use="//ItemKey"/>

The matching template looks like this:

<xsl:template mode="keys" match="*">
                ##############################
                There is an item to be processed here
                <xsl:variable name="old_doc_node"
select="."></xsl:variable>
                <xsl:variable name="keytest"
select="$old_doc_node/ItemKey"></xsl:variable>
                Key test is:  <xsl:value-of select="$keytest"/>
                <!--<xsl:variable name="new_doc_node"
select="$new_file//ItemKey"></xsl:variable>-->
                <xsl:for-each select="$new_file">
                        <xsl:variable name="new_doc_node"
select="key('test', $keytest)"></xsl:variable>
                        Test Key:               <xsl:value-of
select="$keytest"/>
                        Match:                  <xsl:value-of
select="$new_doc_node"/>
                        ###############################
                </xsl:for-each>
</xsl:template>

An excerpt of the output is:

<?xml version="1.0" encoding="utf-8"?>
                ##############################
                There is an item to be processed here
                
                Key test is:  111222
                        Test Key:               111222
                        Match:                  111222
                        ###############################
                
                ##############################
                There is an item to be processed here
                
                Key test is:  111333
                        Test Key:               111333
                        Match:                  111222
                        ###############################

What seems to be happening is that the ItemKey is correctly picked up
from the first file, a "match" is made with the second file, but the
printed value of the ItemKey from the second file never changes - so I
am lead to believe that no actual match is occurring (although from my
test data I know that there is a one to one match).

Any help/suggestions gratefully received.

Many thanks

Stephen


Please help Logica to respect the environment by not printing this email  / 
Pour contribuer comme Logica au respect de l'environnement, merci de ne pas 
imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie 
so Logica dabei, die Umwelt zu schützen. /  Por favor ajude a Logica a 
respeitar o ambiente nao imprimindo este correio electronico.



This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>