Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort different elements by the same criteria

Tags:

xml

xslt

I'm trying to do a sort on the following data.

<contents>
   <content>
      <id>
      <text>
   </content>
   <relatedcontent>
      <id>
      <text>
   </relatedcontent>
</contents>

This is just sample data simplified, but you get the idea. Its two different named nodes that contains the same structure. Right now I have created two different templates to treat the content and relatedcontent separetly, but then sorting is also done separetly. Is there an easy way to sort both content and relatedcontent on ids? Lets say the <text> contains a text. How could I then list all the <text>-elements of content and relatedcontent sorted by id?

Thanks!

like image 719
Erik Avatar asked Jan 27 '26 02:01

Erik


1 Answers

Try something like this

<xsl:foreach select="//content | //relatedcontent">
  <xsl:sort select="id" />
  <xsl:value-of select="text" />
</xsl:foreach>

I guess the solution lies in the fact that you "join" //content and //relatedcontent into a single node-set using the union operator |

like image 114
Lukas Eder Avatar answered Jan 28 '26 19:01

Lukas Eder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!