You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Deepthi <de...@gmail.com> on 2012/08/09 21:14:35 UTC
Grouping of xml and count of each
Hi,
i am trying to group xml's with same id and count the number of items in
each group. I am using camel 2.8.0
For Eg:
Input xml:
<order>
<item>
<id>1</id>
<description>test item 1</description>
</item>
<item>
<id>2</id>
<description>test item 1</description>
</item>
<item>
<id>1</id>
<description>test item 1</description>
</item>
<item>
<id>3</id>
<description>test item 1</description>
</item>
</order>
I am trying to achieve it in the following manner:
<from uri="file://[source folder]" />
<split>
<xpath>/order/item</xpath>
<setHeader headerName="asnid">
<xpath>/item/id/text()</xpath>
</setHeader>
<setHeader headerName="itemCount">
<xpath
resultType="java.lang.String">count(/item)</xpath>
</setHeader>
</split>
The above approach is not working. Can I use aggregator, if so how?
Thanks,
Deepthi
--
View this message in context: http://camel.465427.n5.nabble.com/Grouping-of-xml-and-count-of-each-tp5717086.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Grouping of xml and count of each
Posted by Raul Kripalani <ra...@fusesource.com>.
Splitting and aggregating is designed for routing and orchestration purposes,
rather than low-level data processing.
You are better off using XSLT for this use case.
Take a look at this example [1] for an XSL template that does grouping and
counting.
Use an XSLT endpoint [2] in Camel with camel-saxon for XSLT 2.0
compatibility.
Hope that helps.
[1]
http://www.java2s.com/Code/XML/XSLT-stylesheet/Usecountandcurrentgrouptocountgroups.htm
[2] http://camel.apache.org/xslt.html
*Raúl Kripalani*
*Principal Consultant | FuseSource Corp.
raul@fusesource.com | fusesource.com <http://www.fusesource.com/>
skype: raul.fuse | twitter: @raulvk <http://twitter.com/raulvk>,
@fusenews<http://twitter.com/fusenews>
*
blog: F3 - Flashes From the
Field<http://blog.raulkr.net/?utm_source=fusesourceemail&utm_medium=email&utm_campaign=fusesourcemail>
|
aboutme: http://about.me/raulkripalani
<http://twitter.com/fusenews>
On 9 August 2012 20:14, Deepthi <de...@gmail.com> wrote:
> Hi,
>
> i am trying to group xml's with same id and count the number of items in
> each group. I am using camel 2.8.0
>
> For Eg:
> Input xml:
> <order>
> <item>
> <id>1</id>
> <description>test item 1</description>
> </item>
> <item>
> <id>2</id>
> <description>test item 1</description>
> </item>
> <item>
> <id>1</id>
> <description>test item 1</description>
> </item>
> <item>
> <id>3</id>
> <description>test item 1</description>
> </item>
> </order>
>
> I am trying to achieve it in the following manner:
> <from uri="file://[source folder]" />
> <split>
> <xpath>/order/item</xpath>
> <setHeader headerName="asnid">
> <xpath>/item/id/text()</xpath>
> </setHeader>
> <setHeader headerName="itemCount">
> <xpath
> resultType="java.lang.String">count(/item)</xpath>
> </setHeader>
> </split>
> The above approach is not working. Can I use aggregator, if so how?
>
> Thanks,
> Deepthi
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Grouping-of-xml-and-count-of-each-tp5717086.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>