I am using mule to draw information from the database and format it like this - < Pre> In this way there are many records in the form of primary keys with ID, so I have many of these records, each in a separate MuleMessage, I want to group by group_id, Selected messages look like this - I know that I have to create a message group by an aggregator, but I'm not sure how to put group_id in the form of a combined attribute. Do I have to use XSLT Transformer too? Expected this input file This XSLT can create the output you need Output > & lt; Items & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; Color & gt; Blue & lt; / Color & gt; & Lt; City & gt; Chicago & lt; / City & gt; & Lt; / Item & gt;
& lt; Item & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; ID & gt; 2 & lt; / Id & gt; & Lt; ID & gt; 3 & lt; / Id & gt; & Lt; / Item & gt;
& lt; Items & gt; & Lt; Items & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; Color & gt; Blue & lt; / Color & gt; & Lt; City & gt; Chicago & lt; / City & gt; & Lt; / Item & gt; & Lt; Items & gt; & Lt; ID & gt; 2 & lt; / Id & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; Color & gt; Red & lt; / Color & gt; & Lt; City & gt; Chicago & lt; / City & gt; & Lt; / Item & gt; & Lt; Items & gt; & Lt; ID & gt; 3 & lt; / Id & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; Color & gt; Yellow & lt; / Color & gt; & Lt; City & gt; Detroit & lt; / City & gt; & Lt; / Item & gt; & Lt; Items & gt; & Lt; ID & gt; 4 & lt; / Id & gt; & Lt; Group_id & gt; 2 & lt; / Group_id & gt; & Lt; Color & gt; Cyan & lt; / Color & gt; & Lt; City & gt; Washington & lt; / City & gt; & Lt; / Item & gt; & Lt; Items & gt; & Lt; ID & gt; 5 & lt; / Id & gt; & Lt; Group_id & gt; 2 & lt; / Group_id & gt; & Lt; Color & gt; Gray & lt; / Color & gt; & Lt; City & gt; Colorado & lt; / City & gt; & Lt; / Item & gt; & Lt; / Item & gt;
& lt; Xsl: template match = "/" & gt; & Lt; Xsl: Choose Apply-Template = "Items" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "item" & gt; & Lt; Xsl: Selecting each group = "item" group-rate = "group_id" & gt; & Lt; Xsl: element name = "item" & gt; & Lt; Xsl: element name = "group_id" & gt; & Lt; Xsl: Select Value = "Current-Group-Key ()" /> & Lt; / XSL: element & gt; & Lt; Xsl: each selection = "current-group ()" & gt; & Lt; Xsl: element name = "id" & gt; & Lt; Xsl: Select Value = "id" /> & Lt; / XSL: element & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: element & gt; & Lt; / XSL: for each group & gt; & Lt; / XSL: Templates & gt;
& lt; Item & gt; & Lt; Group_id & gt; 1 & lt; / Group_id & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; ID & gt; 2 & lt; / Id & gt; & Lt; ID & gt; 3 & lt; / Id & gt; & Lt; / Item & gt; & Lt; Items & gt; & Lt; Group_id & gt; 2 & lt; / Group_id & gt; & Lt; ID & gt; 4 & lt; / Id & gt; & Lt; ID & gt; 5 & lt; / Id & gt; & Lt; / Item & gt; Edit: If you do not have an input file with all the items, but there are more files with a single item, then you can do something like this:
& lt; Xsl: variable name = "files" select = "archive ('file: ///path/to/files/item*.xml')" /> & Lt; Xsl: template match = "/" & gt; & Lt; Xsl: element name = "item" & gt; & Lt; Xsl: Select each group = "$ files / items" group = "group_id" & gt; & Lt; Xsl: element name = "item" & gt; & Lt; Xsl: element name = "group_id" & gt; & Lt; Xsl: Select Value = "Current-Group-Key ()" /> & Lt; / XSL: element & gt; & Lt; Xsl: each selection = "current-group ()" & gt; & Lt; Xsl: element name = "id" & gt; & Lt; Xsl: Select Value = "id" /> & Lt; / XSL: element & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: element & gt; & Lt; / XSL: for each group & gt; & Lt; / XSL: element & gt; & Lt; / XSL: Templates & gt;
No comments:
Post a Comment