Sorting while replacing the value for an element

M

mischief_at

Hello,

I have the a Problem while sorting when i want to change the value of an object to sort
To give you an idea as to what i mean:

The XML looks something like this

...

<xy:Node Class="Component">
<xy:Field Partnumber="12345"/>
</xy:Node>
<xy:Node Class="Component">
<xy:Field Partnumber="23456"/>
</xy:Node>
<xy:Node Class="special">
<xy:Field Partnumber="34567"/>
<xy:Relation class="wibble">
<xy:Node Class="Component">
<xy:Field Partnumber="13579"/>
</xy:Node>
</xy:Relation>
</xy:Node>

...

To sort this by Partnumber i used

<xsl:for-each select="(xy:Node[contains($prt_str, @Class)])">
<xsl:sort select="string(xy:Field[@Name='PartNumber'])" order="ascending"/>
<xsl:call-template name="displaypart"/>
</xsl:for-each>

Which works as it should and outputs:

12345
23456
34567

Now the problem presented, that for xy:Node[@Class = 'Special'] the Partnumber of the related Component should be used instead the one of Special.
Replacing the partnumber in the display was easy enough which resulted in:

12345
23456
13579

What do i need todo so for the partnumber is not only replaced but is sorted in the right position?

I tried to set an xsl:variable sorting = partnumber if Class != special, and sorting = partnumber of the attached item when class == special. Afterward i thought i could use the $sorting as argument to sort by.
Also i tried to do it with one for-each for component and one for special which also didn't work.

Somehow it seems to me that the sort has to be set immediately after the the xsl:for-each tag since whenever i put something in between the xsl stops working.

Since i am out of ideas by now i hope one of you might be able to help.
 

Neue Beiträge

Zurück