I have started this again, i was trying to get my head round the basics of this and have failed, below is the structure the XML will most likely take. and then what i need to output below that...
<rtpm>
<old>
<simple>
<information>
<name1code>AAA</name1code>
<name1use>N</name1use>
<name2code>BBB</name2code>
<name2use>P</name2use>
<name3code>CCC</name3code>
<name3use>N</name3use>
<name4code>DDD</name4code>
<name4use>N</name4use>
<name5code>EEE</name5code>
<name5use>N</name5use>
</information>
</simple>
</old>
<new>
<simple>
<information>
<name1code>AAA</name1code>
<name1use>N</name1use>
<name2code>BBC</name2code>
<name2use>P</name2use>
<name3code>AFD</name3code>
<name3use>N</name3use>
<name4code>CCC</name4code>
<name4use>N</name4use>
<name5code>EEE</name5code>
<name5use>N</name5use>
</information>
</simple>
</new>
</rtpm>
I would then need this to perform what was previously described and output as
<request>
<query0>BBC</query0>
<use0>P</use0>
<query1>AFD</query1>
<use1>N</use1>
</request>
The code currently in use is as per below but i have no idea how to make it just pick up name1code, 2code etc for the old key and the use to just pick up the use value when a 'not' match is found for the code.
<xsl:key name="old" match="old/simple/information/*" use="." />
<xsl:key name="use" match="new/simple/information/*" use="name()" />
<xsl:template match="/*">
<request>
<xsl:for-each select="new/simple/information/*[not(key('old', .))]">
<xsl:element name="query{position() - 1}">
<xsl:value-of select="." />
</xsl:element>
<xsl:element name="use{position() - 1}">
<xsl:value-of select="key('use', concat(name(), 'use'))" /> <!--2-->
</xsl:element>
</xsl:for-each>
</request>
</xsl:template>
<!--2-->
is the line i can't get my head around.
Thank you too all that have helped so far, you have been a huge help. i say i have failed getting my head round it, but i get what/how this works to a degree, just not how to further it.
Re your followup question: not sure what exactly "following by a tag" means. In any case, the answer is (again) to use a key to match "related" values, for example:
One way is to use a key to look up the old values
Then, to select new elements with values don't occur in the list of old elements, you would simply do this (assuming you were positioned on rtpm)
And in the template that matches this, to create the relevant query element, you would make use of the position() function (as this is relative to the nodes you have just selected, not the position of them in the hierarchy)
Try this XSLT
When applied on your first XML sample, the following is output
In the second case, the following is also output
EDIT: The question has changed somewhat since it was originally asked (It should really have been asked as a new question), but to answer this new question, the expression in
<!-- 2 -->
you are looking for is thisThis is because the current node has a name of "nameXcode", and it needs to be changed to "nameXuse" to look it up in the key. So, you get the text before "code" and then append "use" on the end instead.
However, if the use node you are getting is always going to be the following sibling to the code node, you could just do this
This will work because following-sibling will get the following sibling in the hierarchy for the current node you are on, and not the next one in the nodes you have just selected.