XML : Combine values from different nodes with XSLT

From the following XML I would like to combine the values that has the same reference id:

  <?xml version="1.0" encoding="UTF-8"?>  <catalog>      <cd id="01">          <reference id="01"/>          <title>Empire Burlesque</title>      </cd>      <cd id="01">          <reference id="02"/>          <title>Hide your heart</title>      </cd>      <cd id="01">          <reference id="03"/>          <title>Greatest Hits</title>      </cd>      <cd id="01">          <reference id="04"/>          <title>Still got the blues</title>      </cd>      <cd id="02">          <reference id="01"/>          <value>In stock</value>      </cd>      <cd id="02">          <reference id="02"/>          <value>Out of stock</value>      </cd>      <cd id="02">          <reference id="03"/>          <value>Out of stock</value>      </cd>      <cd id="02">          <reference id="04"/>          <value>In stock</value>      </cd>  </catalog>    

The result has to be like this:

  <cd reference="01" title-cd="Empire Burlesque" stock="In stock"/>  <cd reference="02" title-cd="Hide your heart" stock="Out of stock"/>  <cd reference="03" title-cd="Greatest hits" stock="Out of stock"/>  <cd reference="04" title-cd="Still got the blues" stock="In stock"/>    

How can this be accomplished with XSLT 1.0?

Kind regards, Sjoerd

No comments:

Post a Comment