开发者

XLST transformation from the input xml to output xml

Input xml structure:

<Customer>
   <Order>
      <item><name>ID</name><value>11111</value><item>
   </Order>
   <Order>
      <item><name>ID</name><value>11111</value></item>
   </Order>
    <Order>
      <item><name>ID</name><value>22222</value></item>
   </Order>
   <Order>
      <item><name>ID</name><value>33333</value></item>
   </Order>
</Customer>

Output should be :

<Customer>
   <Order>
      <item><name>ID</name><value>11111</value><item>
   </Order>
   <Order>
      <item><name>ID</name><value>11111</value> </item>
   </Order>
</Customer>

<Customer>
  <Order>
 开发者_如何学编程     <item><name>ID</name><value>22222</value></item>
   </Order>
</Customer>
<Customer>
  <Order>
      <item><name>ID</name><value>33333</value></item>
   </Order>
</Customer>

Here the <Customer>.<Order>.<item>.<value> will come dynamically. Please anyone give a solution for this transformation in xslt based on <Order>.<item>.<value>


This is a standard grouping problem. In XSLT 2.0, use

<xsl:template match="Customer">
 <xsl:for-each-group select="Order" group-by="item/value">
  <Customer>
    <xsl:copy-of select="current-group()"/>
  </Customer>
 </xsl:for-each-group>
</xsl:template>

If you're stuck on XSLT 1.0, it's a bit more tricky: look up "Muenchian Grouping" (or many replies by Dimitre Novatchev to questions on this forum).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜