Match element N with certain name with element N of other XML when XSL merging

norashanghai

New Member
I have two XML documents I need to merge.\[code\]<!-- A.xml --><cm:Process> <cm:Other /> <cm:Elements /> <cm:Request> <!-- stuff --> </cm:Request> <cm:ElementCouldBeHereToo /> <cm:Request> <!-- stuff --> </cm:Request></cm:Process><!-- B.xml --><gateway-orders> <response> <status /> </response> <response> <status /> </response></gateway-orders>\[/code\]The first is the original XML. The requests has been pulled out and sent to a system and the next is the responses. Now I need to merge these two and match request N with response N so I can pull in some info from the responses. The XSL work on A.xml and get B.xml as a parameter. To begin with I'm just trying to create a copy of the correct response in B.xml inside the request in A.xml.The problem I have is that I thought I could use \[code\]position()\[/code\], but realized that won't work since the \[code\]cm:Request\[/code\] elements are mixed with other elements. Is there another way I can use to match up these somehow?This is what I tried:\[code\]<xsl:import href="http://stackoverflow.com/questions/14562763/identity-transform.xsl" /><xsl:param name="responses" /><xsl:template match="cm:Request"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> <xsl:apply-templates select="$responses/*[1]/*[position()]" /> </xsl:copy></xsl:template>\[/code\]There are two problems here.[*]First of all the \[code\]position()\[/code\] won't match up. Is there a way to get the number/position of \[code\]cm:Request\[/code\] elements you're at rather than the number/position of all sibling elements? So that the first \[code\]cm:Request\[/code\] always gives 1 irregardless of if it has any elements in front of it.[*]Secondly I for some reason get a copy of all responses inside each request. If I change \[code\]position()\[/code\] with for example \[code\]1\[/code\], I only get a copy of the first response in each request. What am I doing wrong here?Hoping someone knows what I should do here, cause I'm a bit blank right now and my Google-fu is failing me :PSo to sum up, how can I match up the nth element with name \[code\]blah\[/code\] with the nth child in a parameter node-set?
 
Back
Top