Reputation: 10134
i have the xml in a structure such as this:
<RWFCriteria reportType="ProgramReview">
<item id="36" name="" value="9" type="Milestone" />
<item id="31" name="" value="9" type="Milestone" />
<item id="33" name="" value="11" type="Milestone" />
</RWFCriteria>
and need to it be converted to:
<data>
<release id="9"> <milestone id="36" /> <milestone id="31" /> </release>
<release id="11"> <milestone id="33" /> </release>
</data>
what would the XSLT look like for this transformation?
Upvotes: 0
Views: 172
Reputation: 14272
You need to group the items based on their value attribute. If you are using xslt 1 you can do this using the Muenchian Method which would look something like:
<xsl:key name="item-value" match="item" use="@value" />
<xsl:template match="/RWFCriteria">
<data>
<xsl:for-each select="item[count(. | key('item-value', @value)[1]) = 1]">
<release id="{@value}">
<xsl:for-each select="key('item-value', @value)">
<milestone id="{@id}" />
</xsl:for-each>
</release>
</xsl:for-each>
</data>
</xsl:template>
Upvotes: 1