You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Robert Thullner <rt...@gmx.at> on 2007/12/27 10:24:52 UTC

XPath Splitter

Hi 
 
I have an XML Message that is send over JMS which I would like to be
splitted. The message looks like this
 
<instruction>
    <header1>...</header1>
    <header2>...</header2>
    ...
    <stages>
        <stage>
            <stageInfo1> ... </stageInfo1>
                ...
        </stage>    
    
        <stage>
            <stageInfo1> ... </stageInfo1>
                ...
        </stage>    
    </stages>
</instruction>
 
What I want now is to split the message so that each message contains the
complete header and one stage. So I want n message, where n is the number of
stages in my document. But each message should contain the header. Is that
possible using the XPath Splitter alone?
Or should I use a ContentFilter where I filter the header out, the use a
splitter for the stages only and afterwards use a ContentEnricher to bring
the header information into the message again?
 
Do you have any suggestions?
Thanks
Robert

Re: XPath Splitter

Posted by Roman Kalukiewicz <ro...@gmail.com>.
2007/12/27, Robert Thullner <rt...@gmx.at>:
> Hi
>
> I have an XML Message that is send over JMS which I would like to be
> splitted. The message looks like this
>
> <instruction>
>     <header1>...</header1>
>     <header2>...</header2>
>     ...
>     <stages>
>         <stage>
>             <stageInfo1> ... </stageInfo1>
>                 ...
>         </stage>
>
>         <stage>
>             <stageInfo1> ... </stageInfo1>
>                 ...
>         </stage>
>     </stages>
> </instruction>
>
> What I want now is to split the message so that each message contains the
> complete header and one stage.
>
> Do you have any suggestions?

What I did in very similar case is I sent such message to XSLT
endpoint first. That XSLT looks like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0" xmlns:agg="http://activemq.apache.org/camel/schema/aggregator">
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <agg:aggregator>
            <xsl:apply-templates select="/instruction/stages/stage"/>
        </agg:aggregator>
    </xsl:template>

    <xsl:template match="/instruction/stages/stage">
        <instruction>
            <xsl:copy-of select="/instruction/*[name() != 'stages' ]"/>
            <stages>
            <xsl:copy-of select="."></xsl:copy-of>
            </stages>
        </instruction>
    </xsl:template>
</xsl:stylesheet>

Then I split using XPath like "/agg:aggregator/*"

I'm not really sure if you can find such XPath/XQuery expression that
will split your original message to what you need.

Hope it helps.
Roman