How to compare the value of two nodes in XSLT

Tags: xslt xslt-2.0

I am new to XSLT. I need help comparing the value of two nodes' values in XML.

My sample XML:

<?xml version="1.0" encoding="utf-8"?>
<G1Export xmlns="">
    <AgencyGroup xmlns="">
    	<Agency xmlns="">
    		<RecordType xmlns="">RecordType</RecordType>
    		<OrgId xmlns="">123</OrgId>
    <BranchGroup xmlns="">
    	<BranchCode xmlns="">
    		<OrgId xmlns="">123</OrgId>

In the above XML file I need to compare the values of the OrgId node under the <AgencyGroup> node to the one under the <BranchGroup> node.

I tried to used the compare() method, but it gives me the reult of 1. The actual result must be 0 (for equal). I am using XSLT 2.

//G1Export/compare(AgencyGroup//OrgId, BranchGroup//OrgId)

result = 0

Edited: There were 2 mistakes in the xslt 1. For brnchOrgId you were using AgencyGroup instead of BranchGroup 2. For the compare() you should have =0 and not ='0'

Corrected xslt:

<xsl:template match="/">
    	<xsl:element name="PICRESPONSE" namespace="">
    		<xsl:for-each select="//G1Export/AgencyGroup">
    			<xsl:if test="count(.) &gt; 0">
    				<!--org_id variable-->
    				<xsl:variable name="orgId" select="string(/G1Export/AgencyGroup/Agency/OrgId)"/>
    				<xsl:element name="EXPORTRESPONSE" namespace="">; <xsl:for-each select="//G1Export/BranchGroup">
    						<xsl:if test="count(.) &gt; 0">
    							<xsl:variable name="brnchOrgId" select="string(/G1Export/BranchGroup/BranchCode/OrgId)"/>								
    							<!--Put the Branch information inside the current agency node only if branch belong to current Agency-->
    							<xsl:if test="compare($brnchOrgId,$orgId)=0">asda
    								<xsl:value-of select="'orgid is same as branchogid'"/>


<?xml version="1.0" encoding="UTF-8"?>
<PICRESPONSE xmlns="">
    <EXPORTRESPONSE>; orgid is same as branchogid</EXPORTRESPONSE>

Hope this helps.

Some operators will not allow you tcp sockets at all but let HTTP connections through.

J2ME is pretty much supported everywhere. I´ve ported some applications to Korean and Hebrew, so my advice is this:

  • Get in contact with service provider in the market you wish enter, they can give you plenty of information about handsets and distribution, data tariffs, etc;
  • TCP connection is available on every J2me capable device I´ve seen, but you should confirm that for your target handsets before porting to them;
  • You should REALLY be carefull when localising your application, bad translations will make your users hate you

I´ll will edit this answers as I think of more advice, if you wish.

This video can help you solving your question :)
By: admin