Have you tried something like this [1]? You need to add another XSLT
processing after you get the original output.

[1] -
https://stackoverflow.com/questions/1571083/how-to-remove-root-element-from-xml-file

Regards,
Gihan

On Mon, Jan 22, 2018 at 8:12 AM, Vinod Kavinda <vi...@wso2.com> wrote:

> Hi Vikram,
> This is happening because your XPath generates multiple elements with
> below structure, which not your desired output.
> *                        <Detail>*
> * <a>26</a>*
> * <b>box</b>*
> * <c>2019-01-17T00:00:00</c>*
> * </Detail> *
>
> In an XML point of view, you are expecting an xml content like below,
> which is not a valid XML content since it does not have a root element. You
> can test this with an online XPath evaluator and verify.
>
> *                         <Detail>*
> * <a>40</a>*
> * <b>car</b>*
> * <c>2019-01-17T00:00:00</c>*
> * </Detail>*
> * <Detail>*
> * <a>37</a>*
> * <b>table</b>*
> * <c>2019-01-17T00:00:00</c>*
> * </Detail>*
>
>
> I don't think you can achieve your requirement with the enrich mediator
> since it only supports Xpaths. Please try using the Payload Factory
> mediator[1] with Jsonpath. Then you can extract the "Detail" element from
> the converted JSON and set it to the body.
>
> [1] - https://docs.wso2.com/display/EI611/PayloadFactory+Mediator
>
> On Sun, Jan 21, 2018 at 8:37 PM, vikram nayak <nayak.vikr...@yahoo.in>
> wrote:
>
>>
>>
>> On Sunday, 21 January 2018 8:14 PM, vikram nayak <nayak.vikr...@yahoo.in>
>> wrote:
>>
>>
>> Hi All,,
>>
>> I have output like below from my xslt :
>>
>> <?xml version='1.0' encoding='utf-8'?>
>> <soapenv:Envelope xmlns:soapenv="http://schemas.
>> xmlsoap.org/soap/envelope/">
>> <soapenv:Body>
>> <Result>
>> <Detail>
>> <a>40</a>
>> <b>car</b>
>> <c>2019-01-17T00:00:00</c>
>> </Detail>
>> <Detail>
>> <a>37</a>
>> <b>table</b>
>> <c>2019-01-17T00:00:00</c>
>> </Detail>
>> <Detail>
>> <a>35</a>
>> <b>book</b>
>> <c>2019-01-17T00:00:00</c>
>> </Detail>
>> <Detail>
>> <a>26</a>
>> <b>box</b>
>> <c>2019-01-17T00:00:00</c>
>> </Detail>
>> </Result>
>> </soapenv:Body>
>> </soapenv:Envelope>
>>
>> which gets converted into below json in postman :
>>
>> {
>>     "Result": {
>>         "Detail": [
>>             {
>>                 "a": "40",
>>                 "b": "car",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "37",
>>                 "b": "table",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "35",
>>                 "b": "book",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "26",
>>                 "b": "box",
>>                 "c": "2019-01-17T00:00:00"
>>             }
>>         ]
>>     }
>> }
>>
>> but in my desired output response . I do not want root element "Result".
>>
>> Desired output :
>>
>> {
>>     "Detail": [
>>             {
>>                 "a": "40",
>>                 "b": "car",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "37",
>>                 "b": "table",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "35",
>>                 "b": "book",
>>                 "c": "2019-01-17T00:00:00"
>>             },
>>             {
>>                 "a": "26",
>>                 "b": "box",
>>                 "c": "2019-01-17T00:00:00"
>>             }
>>         ]
>>     }
>> }
>>
>> Going through some online documents I tried below enrich after xslt.
>>
>> <enrich>
>>     <source clone="true" xpath="$body/Result/Detail"/>
>>     <target type="body"/>
>> </enrich>
>>
>> But it gives only one element from my output  like below :
>>
>> {
>>     "Detail": {
>>         "insuranceNumber": "40",
>>         "policyName": "Laptop insurance - 4 star",
>>         "agreementValidTill": "2019-01-17T00:00:00"
>>     }
>> }
>>
>> Please guide.
>>
>> Thanks,
>> Vikram
>>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Vinod Kavinda
> Senior Software Engineer
> *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.*
> Mobile : +94 (0) 712 415544
> Blog : http://soatechflicks.blogspot.com/
> [image: http://wso2.com/signature]
> <http://wso2.com/signature>
>
>
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
W.G. Gihan Anuruddha
Associate Technical Lead | WSO2, Inc.
M: +94772272595
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to