Click to See Complete Forum and Search --> : How can I join (merge) two node-sets into another node-set?


DavinChurch
April 5th, 2008, 11:00 AM
I've read in (via document()) two node-sets and put them in variables. Now I'd like to combine them into a single node-set (not as text or a result-tree-fragment) variable by linking them together via a key field. There's got to be an easy way to do this. My data looks something like this:

$names:

<row><col type="id">a</col><col type="name">First name</col></row>
<row><col type="id">b</col><col type="name">Second name</col></row>
<row><col type="id">c</col><col type="name">Third name</col></row>
<row><col type="id">d</col><col type="name">Forth name</col></row>

$numbers:

<row><col type="id">c</col><col type="qty">33</col></row>
<row><col type="id">a</col><col type="qty">11</col></row>

What I'd like to get back (in some form) is:
$together:

<row><col type="id">c</col><col type="name">Third name</col><col type="qty">33</col></row>
<row><col type="id">a</col><col type="name">First name</col><col type="qty">11</col></row>

Now I think I could come up with a whole stylesheet to do this job for direct translation purposes, but I'm actually needing to imbed this in a large HTML-output stylesheet (that's running off a completely different XML file) and use the resulting node-set in a for-each loop. How might I do this in some easy fashion?

(I'm running IE7 under XP, but it'd be nice if it were somewhat portable. All the XML/XSL files are local and the machine may not be web-connected when running, in case that matters for external namespaces or the like.)

Alain COUTHURES
April 29th, 2008, 02:43 AM
You will have to use msxml:node-set to use the resulting node-set in a for-each loop.

DavinChurch
April 29th, 2008, 10:28 AM
Thanks. I was hoping for an alternative that didn't require msxml:node-set because I'm not sure I can have it available everywhere I need to use this. Maybe I'll be able to come up with alternative somehow, probably with a triply-nested for-each, or something like that.

Alain COUTHURES
April 30th, 2008, 01:41 AM
You can also use exslt:node-set if not with a Microsoft XML parser.