Hi Sudharma,

Thanks for the response. I was able to get this done using dynamic XSLT tag
as <xsl:element name="{$parentWrappingElement}">.

Thanks.

On Mon, Aug 21, 2017 at 12:54 PM, Sudharma Subasinghe <sudhar...@wso2.com>
wrote:

> Hi Lahiru,
>
> You can try the script mediator to build the expected response which is
> better than duplicating XSLTs.
>
> Thanks
> Sudharma
>
> On Mon, Aug 21, 2017 at 9:15 PM, Lahiru Sandaruwan <lahi...@wso2.com>
> wrote:
>
>> Hi,
>>
>> I want to change the responding content type based on Accept header(JSON
>> or XML), sent in the request. My concern is the wrapping element of arrays.
>> For example,
>>
>> Required Json response,
>>
>> [
>>     {
>>         "aaa" : "23432",
>>         "bbb" : "234",
>>         "ccc" : "asdfas"
>>     },
>>     {
>>         "aaa" : "23432",
>>         "bbb" : "234",
>>         "ccc" : "asdfas"
>>     },
>>     {
>>         "aaa" : "23432",
>>         "bbb" : "234",
>>         "ccc" : "asdfas"
>>     }
>> ]
>>
>> Required XML response,
>>
>> <accounts>
>>     <account>
>>         <aaa>2342344</aaa>
>>         <bbb>23432432432</bbb>
>>         <ccc>asdasdasd</ccc>
>>     </account>
>>     <account>
>>         <aaa>234324</aaa>
>>         <bbb>32432</bbb>
>>         <ccc>asdfasdf</ccc>
>>     </account>
>>     <account>
>>         <aaa>234</aaa>
>>         <bbb>34234</bbb>
>>         <ccc>asdf</ccc>
>>     </account>
>> </accounts>
>>
>> If I build local message with jsonArray and jsonElement as below, I could
>> get the JSON response correctly. But XML response would be wrong, as it is
>> not wrapped with accounts and account tags.
>>
>> <jsonArray>
>>     <jsonElement>
>>         <aaa>2342344</aaa>
>>         <bbb>23432432432</bbb>
>>         <ccc>asdasdasd</ccc>
>>     </jsonElement>
>>     <jsonElement>
>>         <aaa>234324</aaa>
>>         <bbb>32432</bbb>
>>         <ccc>asdfasdf</ccc>
>>     </jsonElement>
>>     <jsonElement>
>>         <aaa>234</aaa>
>>         <bbb>34234</bbb>
>>         <ccc>asdf</ccc>
>>     </jsonElement>
>> </jsonArray>
>>
>> I'm building this message using a XSLT. I can think of using 2 XSLTs for
>> two types. But that will duplicate XSLT just for this. Is there a better
>> approach?
>>
>> Thanks.
>> --
>> --
>>
>> Lahiru Sandaruwan
>> Associate Technical Lead,
>> WSO2 Inc., http://wso2.com
>>
>> lean.enterprise.middleware
>>
>> m: +94773325954 <+94%2077%20332%205954>
>> e: lahi...@wso2.com b: https://medium.com/@lahirugmg
>> in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146
>>
>>
>
>
> --
> Sudharma Subasinghe,
> Software Engineer,
> WSO2 Inc.
> Email: sudhar...@wso2.com <hasi...@wso2.com>
> Mobile : +94 710 565 157 <%2B94%20718%20210%20200>
>



-- 
--

Lahiru Sandaruwan
Associate Technical Lead,
WSO2 Inc., http://wso2.com

lean.enterprise.middleware

m: +94773325954
e: lahi...@wso2.com b: https://medium.com/@lahirugmg
in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to