Yes it would copy the matching elements.
For example :
<foo>
<customer value ="1" type="regular"/>
<customer value ="2" />
<customer value ="3" type="regular"/>
<customer value ="4" type="regular"/>
<customer value ="5" />
</foo>
Suppose we need to get the customer elements with attribute "type". Here we
can use the following payload factory mediator.
<payloadFactory media-type="xml">
<format>
<Customers>$1</Customers>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="//customer[@type]" evaluator="xml"/>
</args>
</payloadFactory>
Thanks,
Maheeka
Maheeka Jayasuriya
Software Engineer
Mobile : +94777750661
On Wed, May 6, 2015 at 11:12 AM, Srinath Perera <[email protected]> wrote:
> I understood how it work with foreach (with transformation). Thanks!! Need
> to put this in right places in docs.
>
> Can we do that with just payload factory as well? If xapth matches
> multiple values, does it copy everything?
>
> --Srinath
>
>
> On Wed, May 6, 2015 at 10:55 AM, Maheeka Jayasuriya <[email protected]>
> wrote:
>
>> Hi Srinath,
>>
>> Above transformation can be achieved by using a payload factory mediator.
>>
>> <payloadFactory media-type="xml">
>> <format>
>> <Customers>$1</Customers>
>> </format>
>> <args>
>> <arg xmlns:ns="http://org.apache.synapse/xsd"
>> expression="//customer" evaluator="xml"/>
>> </args>
>> </payloadFactory>
>>
>> If the customer elements inside outer foo needs to be changed the
>> following synapse config can be used. Here we iterate over customer
>> elements and apply a transformation.
>>
>> <foreach xmlns:ns="http://org.apache.synapse/xsd" xmlns:m0="
>> http://services.samples" expression="//foo/customer">
>> <sequence>
>> <payloadFactory media-type="xml">
>> <format>
>> <cust value="$1"/>
>> </format>
>> <args>
>> <arg expression="//customer/@value" evaluator="xml"/>
>> </args>
>> </payloadFactory>
>> </sequence>
>> </foreach>
>>
>> Thanks,
>> Maheeka
>>
>>
>>
>> Maheeka Jayasuriya
>> Software Engineer
>> Mobile : +94777750661
>>
>> On Wed, May 6, 2015 at 10:00 AM, Srinath Perera <[email protected]> wrote:
>>
>>> Could u explain how?
>>>
>>>
>>> I have input that looks like following ( # of customers will vary)
>>>
>>> <foo>
>>> <customer value ="1" />
>>> <customer value ="1" />
>>> <customer value ="1" />
>>> ....
>>> </foo>
>>>
>>> I want to construct following
>>>
>>> <Customers>
>>> <customer value ="1" />
>>> <customer value ="1" />
>>> <customer value ="1" />
>>> ....
>>>
>>> </Customers>
>>>
>>> How can I do it? Also it is good if we can support this within payload
>>> mediator if possible.
>>>
>>> --Srinath
>>>
>>>
>>>
>>> On Wed, May 6, 2015 at 9:55 AM, Malaka Silva <[email protected]> wrote:
>>>
>>>> Hi Srinath,
>>>>
>>>> I think use case you mentioned can be handled with FOR-EACH mediator
>>>> which will be introduced in ESB 4.9.0
>>>>
>>>> On Wed, May 6, 2015 at 9:46 AM, Srinath Perera <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Kasun,
>>>>>
>>>>> I have been working on ESB script last week, and two comments.
>>>>>
>>>>> 1. If we use payload factory mediator, and if Xpath matches more than
>>>>> one results, what do we do? It is a valid usecase if someone want to copy
>>>>> N
>>>>> elements from request to response via payload factory.
>>>>>
>>>>> 2. Enrich has too many parameters, and some combinations does not
>>>>> work. ( see below).
>>>>>
>>>>> <enrich>
>>>>> <source [clone=true|false]
>>>>> [type=custom|envelope|body|property|inline] xpath="" property="" />
>>>>> <target [action=replace|child|sibiling]
>>>>> [type=custom|envelope|body|property|inline] xpath="" property="" />
>>>>> </enrich>
>>>>>
>>>>> I think we can remove "type" and "property" and support both via Xpath
>>>>> only. We can break Xpath to <source>/foo/bar where source can be
>>>>> $envelope,
>>>>> $body $header $getProperty("bar") etc ( $envelope etc is already there).
>>>>>
>>>>> If we do this correct, we can refer to anything in ESB environment via
>>>>> Xpath of the format <source>/foo/bar. Then we can make this consistent
>>>>> across the language.
>>>>>
>>>>> WDYT?
>>>>>
>>>>> --Srinath
>>>>>
>>>>> --
>>>>> ============================
>>>>> Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
>>>>> Site: http://people.apache.org/~hemapani/
>>>>> Photos: http://www.flickr.com/photos/hemapani/
>>>>> Phone: 0772360902
>>>>>
>>>>> _______________________________________________
>>>>> Architecture mailing list
>>>>> [email protected]
>>>>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Best Regards,
>>>>
>>>> Malaka Silva
>>>> Senior Tech Lead
>>>> M: +94 777 219 791
>>>> Tel : 94 11 214 5345
>>>> Fax :94 11 2145300
>>>> Skype : malaka.sampath.silva
>>>> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
>>>> Blog : http://mrmalakasilva.blogspot.com/
>>>>
>>>> WSO2, Inc.
>>>> lean . enterprise . middleware
>>>> http://www.wso2.com/
>>>> http://www.wso2.com/about/team/malaka-silva/
>>>> <http://wso2.com/about/team/malaka-silva/>
>>>>
>>>> Save a tree -Conserve nature & Save the world for your future. Print
>>>> this email only if it is absolutely necessary.
>>>>
>>>
>>>
>>>
>>> --
>>> ============================
>>> Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
>>> Site: http://people.apache.org/~hemapani/
>>> Photos: http://www.flickr.com/photos/hemapani/
>>> Phone: 0772360902
>>>
>>
>>
>
>
> --
> ============================
> Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
> Site: http://people.apache.org/~hemapani/
> Photos: http://www.flickr.com/photos/hemapani/
> Phone: 0772360902
>
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture