## Re: [xsl] Sorting by document order of some other element

 Subject: Re: [xsl] Sorting by document order of some other element From: "Peter Hunsberger" Date: Tue, 26 Jun 2007 10:17:21 -0500
On 6/25/07, Eric Brichemier <eric.brechemier@xxxxxxxxx> wrote:
Hi Peter,

```I am not sure to understand this part
> the element name is unknown but will match in both sets
but based on provided sample and my fuzzy understanding, it seems like
your problem would be much simpler to solve by actually```

```- iterating on the first set, where elements are correctly ordered,
- and for each element, copying the value found in the second set
where [replace with your condition, maybe id attribute is
identical...]
```
```I had to go back and look at the original code to figure out why it
wasn't doing this.  Turns out I missed two requirements:```

```- In some instances there may be multiple matches of the second set,
it's not a one to one correspondence.```

```- there is considerable manipulation of the data contained within the
second set.  Again this can be handdled```

```both of thse can still be handled by matching against the first set of
data, but I can see why the author didn't do it this way; the natural
context for this particular  problem is the second set of data.  I'm
going to see if I can invert the context as you suggest and get it to
work as expected...```

Kind Regards,

Eric Brichemier

```On 6/25/07, Peter Hunsberger wrote:
> Hi everyone,
>
> it's been a couple of years since I've had need to consult with all
> the wise guru's here, but I've got a question on a sorting problem
> that I can't see a simple answer to at the moment.  Basically, I've
> got two sets of elements, the element name is unknown but will match
> in both sets.  I would like to walk the second set of elements (via a
> for-each) and copy them in the order of the corresponding order of the
> first set of identically named elements.  There will be an attribute
> (say "id") that will have a one to one correspondence between both
> sets of elements  .  Eg:
>
> Input:
>
> <doc>
>   <set1>
>       <element id="4"/>
>       <element id="7"/>
>       <element id="1"/>
>       <element id="3"/>
>       <element id="2"/>
>   </set1>
>   <set2>
>       <element id="1">other stuff a</element>
>       <element id="4">other stuff b</element>
>       <element id="3">other stuff c</element>
>       <element id="2">other stuff d</element>
>       <element id="7">other stuff e</element>
>   </set2>
> </doc>
>
> Desired output:
>
>   <set2>
>       <element id="4">other stuff b</element>
>       <element id="7">other stuff e</element>
>       <element id="1">other stuff a</element>
>       <element id="3">other stuff c</element>
>       <element id="2">other stuff d</element>
>   </set2>
>
> Answers can be restricted to XSLT 2.0....
>
> --
> Peter Hunsberger```

```--
Peter Hunsberger```