0

This is the sample XML that I am working on:

<NewDataSet>
  <Table>
    <content_id>ID_001</content_id>
    <record_id>Value_1</record_id>
  </Table>
  <Table>
    <content_id>ID_001</content_id>
    <record_id>Value_2</record_id>
  </Table>
  <Table>
    <content_id>ID_002</content_id>
    <record_id>Value_3</record_id>
  </Table>
</NewDataSet>

I would like to transform this to

<Results>
    <Record>
        <id>ID_001
        </id>
        <item>Value_1
        </item>
        <item>Value_2
        </item>
    </Record>
    <Record>
        <id>ID_002
        </id>
        <item>Value_3
        </item>
    </Record>
</Result>

What's causing the trouble is that I am not able to do a GROUP BY <content_id> in the XSL to get the result.

Could I get any help in this?

zx485
  • 28,498
  • 28
  • 50
  • 59
Swayam
  • 1
  • Look up the tag [_muenchian-grouping_](http://stackoverflow.com/questions/tagged/muenchian-grouping) that I added to find a solution to your problem. – zx485 Apr 12 '17 at 05:21

1 Answers1

0

You didn't specify the version of XSLT, but if you can use version 2.0, then use for-each-group.

See e.g. http://www.w3.org/TR/xslt20/#element-for-each-group (or countless examples in the web, even on stacktrace).

To get proper grouping use group-by="Table/content_id" attribute.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41
  • Thanks ! this if for 1.0. – Swayam Apr 12 '17 at 06:09
  • I got that group-by clause. That would help, but how to have two separate elements for . i.e. ID_001 Value_1 Value_2 group-by would have these two values value_1 and value_2 together. I would want them as separate items being grouped under content_id – Swayam Apr 12 '17 at 06:12