compare values in two xmls in wso2 esb sequence - wso2

I need to compare two xmls in a sequence and store the number of matches in a variable. can this be achieved through sequence.
for example first sequence will be:
<employees>
<employee><id>1</id><name>abc</name></employee>
<employee><id>2</id><name>def</name></employee>
<employee><id>3</id><name>ghi</name></employee>
</employees>
second xml
<employees>
<employee><id>1</id><name>abc</name></employee>
<employee><id>3</id><name>ghi</name></employee>
</employees>
when I compare these two xmls I need to get a count value of 2. How to achieve this.

You can achieve this class mediators. Write your logic in your java class and store the property in synapse context in your custom class.

Related

How to map xml attribute with wso2 data mapper?

I'm using wso2 data-mapper to map input schema with output schema. problem here is we are unable to map with xml attributes(either it can be in input schema or output schema)
We are able to map with element based xml but unable to map with attribute values
Below link will show you the input schema and output schema
https://drive.google.com/file/d/1Dmupfl71Ww_mLQB0gRL1RnmaebrUnzwh/view?usp=sharing
I tried mapping xml elements to attributes on both Windows and Mac and both seem to work fine. I would advise to start with a small version of your xml tree and expand to see what the problem could be. One difference that stands out: I put sample data in my XML which does not seem to be the case in your example (since it says 'NULL' everywhere).
XML input:
<test>
<owner>theowner</owner>
<status>working</status>
</test>
XML output:
<test>
<Users owner="me" status="working" />
</test>

Optional column in pdf after fop xslt transformation

I have a xslt transformation from xml to pdf using apache fop. Whether is possible to add codnition to xslt transormation? I want to not display column in result pdf if all values in column equals zero. It's possible?
Yes, it is possible. In fact, you can do declarative/functional programming logic with XSLT using templates, functions and conditionals. Since you did not provide any example code, I will suppose that you have a table element in your xslt, and you want to show it only if there is some non-zero value to be displayed.
In this case, you should use an recursive template to walk along the list in your xml, and keep checking with XPath if the values are equal to zero. If you find zero, call this same template for the next value, if not, call the template that builds the table for you.
Notice that to use condition, you can use xsl:for-each, xsl:when or xsl:if elements to make the decision given the XPath expression. The xsl:template is used for iterating recursively with parameters, given that instance variables do not exist in xsl.

Using XSLT how do we render CDATA tag?

Using XSLT how do we render CDATA tag?
In xslt I dont want to create CDATA tag using text or declaring in xml
output tag using cdata-section-elements,
it should read it dynamically from input, if element value is around CDATA than
then xslt should render the same, as shown below
Input:
<A><![CDATA[Hello World]]></A>
XSLT Output :
<A><![CDATA[Hello World]]></A>
The data model XSLT/XPath/XQuery operate on does not know any CDATA sections so you can't simply preserve them as the tree you operate on simply contains a text node in both cases (i.e. for <foo>a & b</foo> and <foo><![CDATA[a & b]]></foo> the tree is a foo element containing a single text child node with the string value a & b).
So there is no way in pure XSLT to achieve what you want, unless you pre-process the input to convert CDATA sections into some structure like elements the XSLT data model allows you to detect and distinguish. Andrew Welch has http://andrewjwelch.com/lexev/ to do that in a Java environment.
Thus if you use an XSLT 2.0 processor like Saxon 9 with Java you could use that approach.

How we can override a WSO2 DSS #nil=true value

i am using postages Db for my services.When Null defined for any fields DSS giving Some object so my front end also getting same object .But they are expecting "NULL" instead of this they are getting {#nil":"true"}
How can i get NULL value As NULL only and its creating its own name space also for this row
http://www.w3.org/2001/XMLSchema-instance"
username password
=========== ============
NULL NULL
kk a123
for above i am getting like this fro WSO2dss side
<Datalist>
<username xmlns="http:sps.in" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<password xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</Datalist>
from my wso2esb side i am getting JSON like this
{"Body":{"Datalist":{"username":{"#nil":"true"},"password":{"#nil":"true"}}}}
But my front end service expecting in this below format where can modify for above this
{"Body":{"Datalist":{"username":"NULL","password":"NULL"}}}
In XML, the standard/recommended way to indicate that the value of a particular XML node is NULL, is via the notation [xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"]. If any standard XML parser comes across this particular notation, the element which contains the aforesaid notation is treated as an element with NULL as its value. This is particularly useful, when there are values such as "NULL" (not the actual NULL but a string containing the characters, "N","U","L","L") as there's no way to distinguish the real NULL values and "NULL" character streams.
Therefore, the best way to handle this scenario would be to check for #nil attribute at client side while parsing the JSON content that returns as the response of the web service invocation. Alternatively, you can add an XSLT transformation at the data service query level to transform the response (in XML format which gets processed internally within DSS before returning JSON content) the way you want so that you'll be able to add any custom rules and transform the response before it is returned to the client side. You can refer to the sample data service named "ExcelSampleService.dbs" located in "DSS_HOME/samples/dbs/excel/" directory in the product package for an example on how this is done.
Hope this helps!
Regards,
Prabath
It worked for me. I just put that two atributtes (xsi:nil, xmlns:xsi) into my XML by changing my AS (Application Server) like this:
public static OMElement addAttributeNull(OMElement parametro){
parametro.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", null);
parametro.addAttribute("xsi:nil", "true", null);
return parametro;
}

how to retrieve xml node if it contains entity in xml node?

I have an xml file in this format
<xml>
<entity>&acces;</entity>
</xml>
I am trying to retrieve the value of entity using <xsl:value-of select="xml/entity"> but it's returning empty string. Any hint how to achieve this?
Is that what your XML looks like?
It is missing the entity declaration or DTD reference that would define that entity. Your XML parser should throw an error, but may just be silently "skipping" it, so when you attempt to obtain the value, it is empty.