[
https://issues.apache.org/jira/browse/CAMEL-6794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13860333#comment-13860333
]
Rene Avontuur commented on CAMEL-6794:
--------------------------------------
I am currently writing an aggregation strategy that uses internally an
XsltBuilder, in a similar way as the XsltComponent does.
It seems to meet fully the above requirements.
On request I can share the code. It might fit well in the
org.apache.camel.util.toolbox package. Please let me know if that's a good
idea.
The route and the xslt will look like:
{code}
Namespaces ns = new Namespaces("one",
"http://camel.apache.org/schema/one");
XPathBuilder xPathSplitter = new XPathBuilder("//one:other");
xPathSplitter.setNamespaces(ns.getNamespaces());
AggregationStrategy aggregationStrategy =
XsltAggregationStrategies.xsltAggregation(getContext())
.enableSaxon()
.setXslt("org/apache/camel/component/xslt/saxon-merger.xsl")
.setFragmentName("other");
from("direct:splitter")
.setProperty(XsltAggregationStrategy.PROPERTY_INITIAL_DOCUMENT,
simple(xmlDataInitial))
.split(xPathSplitter, aggregationStrategy)
.log(LoggingLevel.INFO, "processing splitted node:
${body}")
.end()
.to("mock:resultSplitter");
{code}
{code:xml}
<xsl:param name="other"/>
<xsl:template match="list">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
<xsl:element name="item">
<xsl:element name="name">
<xsl:value-of select="$other/one:test/text()"/>
</xsl:element>
<xsl:element name="price">
<xsl:value-of select="$other/one:price/text()"/>
</xsl:element>
</xsl:element>
</xsl:copy>
</xsl:template>
{code}
> XSLT Aggregation Strategies?
> ----------------------------
>
> Key: CAMEL-6794
> URL: https://issues.apache.org/jira/browse/CAMEL-6794
> Project: Camel
> Issue Type: New Feature
> Components: camel-core
> Affects Versions: 2.12.1
> Reporter: Oliver Jelinski
>
> Hi Camel team,
> my wish for a new feature already came up a long time ago, in CAMEL-2820, but
> this was closed, because the requester didn't give enough information on
> this. So I try it again, with a bit more info...
> I am processing xml via camel a lot and I'm working a lot with the xslt
> component for transformations. This works fine and I think it is solved by
> you in a very elegant way.
> But very often I also need to split my xml for processing of the
> maxOccurs="unbounded"-Elements one-by-one. This also works fine, but when it
> comes to aggregating the elements again, I need to write a
> java-AggregationStrategy for that.
> Basically, what the java AggregationStrategy does, would be also achievable
> with XSLT: having an old exchange (that is null for the first aggregation)
> and a new exchange that are however aggregated to a new object that has the
> same type as the body of the old exchange.
> In XSLT you can transform two (or more) files into one new file, So it would
> be totally possible to process one xml-file of namespace x with root element
> x:a and another xml-file with namespace y with root element y:b to a target
> file which also has the root-element x:a. This could be repeated n times and
> would result in an element x:a. -- basically the same behaviour as the java
> AggregationStrategies.
> So my wish would be to have something like
> <split strategyRef="xslt:MyTransformation.xslt" >
> ...
> </split>
> If I had that, I would save a lot of marshal/unmarshal operations. I would be
> glad, if you took this into consideration.
> Best regards,
> Oliver
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)