change inside tag values or node values of xml in wso2 esb using any script works on wso2 esb
This is My Source XML
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>IND</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>AFG</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>AUT</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
And i would like to replace the tag value in the following path :/soapenv:Body/request/changes/change/values/country.recordId
I tried with doing enrich mediator replace property. But it is not changing any tag values in my Source XML. Please suggest any methods to achieve this
My target xml should be Like
<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>1234</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>1235</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>1236</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
</request>
</soapenv:Body>
is it possible to do this by adding some javascript code or using xQuery in wso2 mediators.
Thanks In Advance.
xml xslt integration wso2esb
add a comment |
This is My Source XML
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>IND</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>AFG</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>AUT</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
And i would like to replace the tag value in the following path :/soapenv:Body/request/changes/change/values/country.recordId
I tried with doing enrich mediator replace property. But it is not changing any tag values in my Source XML. Please suggest any methods to achieve this
My target xml should be Like
<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>1234</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>1235</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>1236</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
</request>
</soapenv:Body>
is it possible to do this by adding some javascript code or using xQuery in wso2 mediators.
Thanks In Advance.
xml xslt integration wso2esb
add a comment |
This is My Source XML
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>IND</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>AFG</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>AUT</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
And i would like to replace the tag value in the following path :/soapenv:Body/request/changes/change/values/country.recordId
I tried with doing enrich mediator replace property. But it is not changing any tag values in my Source XML. Please suggest any methods to achieve this
My target xml should be Like
<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>1234</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>1235</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>1236</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
</request>
</soapenv:Body>
is it possible to do this by adding some javascript code or using xQuery in wso2 mediators.
Thanks In Advance.
xml xslt integration wso2esb
This is My Source XML
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>IND</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>AFG</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>AUT</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
And i would like to replace the tag value in the following path :/soapenv:Body/request/changes/change/values/country.recordId
I tried with doing enrich mediator replace property. But it is not changing any tag values in my Source XML. Please suggest any methods to achieve this
My target xml should be Like
<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<request>
<applicationVersion>agidmp-5.0.0.0</applicationVersion>
<serviceName>changeRequestService</serviceName>
<changes>
<change>
<entityName>ChangeRequest</entityName>
<path>ChangeRequest--4</path>
<operation>a</operation>
<values>
<changeRequestName>ChangeRequest-CR-007</changeRequestName>
<changeRequestNumber>ChangeRequest-CR-007</changeRequestNumber>
<changeRequestUID>ChangeRequest-CR-007</changeRequestUID>
<productCategory>20984</productCategory>
<requestCategory.recordId>20032</requestCategory.recordId>
<sourceSystem.recordId>20048</sourceSystem.recordId>
<scopeDescription> Minimum age limit:15Years</scopeDescription>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--7</path>
<operation>a</operation>
<values>
<country.recordId>1234</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--8</path>
<operation>a</operation>
<values>
<country.recordId>1235</country.recordId>
</values>
</change>
<change>
<entityName>ChangeRequestScopeCountry</entityName>
<path>ChangeRequest--4.changeRequestCountryList--9</path>
<operation>a</operation>
<values>
<country.recordId>1236</country.recordId>
</values>
</change>
<change>
<path>ChangeRequest--4.submissionRequestScopeStudyProgramList--5</path>
<operation>a</operation>
<entityName>SubmissionRequestScopeStudyAndProgram</entityName>
<values>
<invStudy.recordId>40037</invStudy.recordId>
</values>
</change>
</changes>
</request>
</soapenv:Body>
is it possible to do this by adding some javascript code or using xQuery in wso2 mediators.
Thanks In Advance.
xml xslt integration wso2esb
xml xslt integration wso2esb
asked Nov 16 '18 at 10:04
DhanaSekharDhanaSekhar
32
32
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Interesting question. There are several routes available. I was going to suggest to pass the recordId as a variable to an xslt but upon careful examination I see that you need to replace multiple 'recordId' elements for presumably different landcodes which is certainly not trivial.
In that case I'd suggest you use an xslt with a lookup table. As I haven't used one of those myself I was curious so I fiddled around with some examples and came up with the following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://example.country"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- copy everything that is not country.recordId -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- create a lookup variable based on the table at the bottom -->
<xsl:key name="id-lookup" match="s:id" use="s:abbr"/>
<xsl:variable name="allrecordids" select="document('')/*/s:recordIds"/>
<!-- replace the country.recordIds -->
<xsl:template match="country.recordId">
<xsl:apply-templates select="$allrecordids">
<xsl:with-param name="curr-label" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="s:recordIds">
<xsl:param name="curr-label"/>
<country.recordId><xsl:value-of select="key('id-lookup', $curr-label)/s:nr"/></country.recordId>
</xsl:template>
<!-- the lookup table -->
<s:recordIds>
<s:id><s:abbr>AFG</s:abbr><s:nr>1234</s:nr></s:id>
<s:id><s:abbr>IND</s:abbr><s:nr>1235</s:nr></s:id>
</s:recordIds>
</xsl:stylesheet>
I made a big assumption here that the 'IND' and 'AFG' always results in the same number so hopefully this helps! At least it was fun :)
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
add a comment |
As you indicated the solution above is not applicable to your specific use case, I came up with a different solution using foreach.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="translate_landcodes" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<foreach expression="//change">
<sequence>
<filter xpath="//country.recordId">
<then>
<property expression="//country.recordId" name="landcode" scope="default" type="STRING"/>
<sequence key="get_landnumber"/>
<enrich>
<source clone="true" property="landnumber" type="property"/>
<target xpath="//country.recordId"/>
</enrich>
</then>
</filter>
</sequence>
</foreach>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I ran into the following bug https://wso2.org/jira/browse/ESBJAVA-5227. Which is fixed in IE 6.20 and newer, but I solved it by moving the database call to a separate sequence:
<sequence name="get_landnumber" xmlns="http://ws.apache.org/ns/synapse">
<dblookup>
<connection>
<pool>
<dsName>jdbc/landcodes_db</dsName>
</pool>
</connection>
<statement>
<sql><![CDATA[select numbercode from translate where lettercode=?]]></sql>
<parameter expression="get-property('landcode')"
type="VARCHAR" xmlns:ns="http://org.apache.synapse/xsd"/>
<result column="numbercode" name="landnumber"/>
</statement>
</dblookup>
</sequence>
Note that you have to define the database connection in configuration/datasources.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335509%2fchange-inside-tag-values-or-node-values-of-xml-in-wso2-esb-using-any-script-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Interesting question. There are several routes available. I was going to suggest to pass the recordId as a variable to an xslt but upon careful examination I see that you need to replace multiple 'recordId' elements for presumably different landcodes which is certainly not trivial.
In that case I'd suggest you use an xslt with a lookup table. As I haven't used one of those myself I was curious so I fiddled around with some examples and came up with the following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://example.country"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- copy everything that is not country.recordId -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- create a lookup variable based on the table at the bottom -->
<xsl:key name="id-lookup" match="s:id" use="s:abbr"/>
<xsl:variable name="allrecordids" select="document('')/*/s:recordIds"/>
<!-- replace the country.recordIds -->
<xsl:template match="country.recordId">
<xsl:apply-templates select="$allrecordids">
<xsl:with-param name="curr-label" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="s:recordIds">
<xsl:param name="curr-label"/>
<country.recordId><xsl:value-of select="key('id-lookup', $curr-label)/s:nr"/></country.recordId>
</xsl:template>
<!-- the lookup table -->
<s:recordIds>
<s:id><s:abbr>AFG</s:abbr><s:nr>1234</s:nr></s:id>
<s:id><s:abbr>IND</s:abbr><s:nr>1235</s:nr></s:id>
</s:recordIds>
</xsl:stylesheet>
I made a big assumption here that the 'IND' and 'AFG' always results in the same number so hopefully this helps! At least it was fun :)
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
add a comment |
Interesting question. There are several routes available. I was going to suggest to pass the recordId as a variable to an xslt but upon careful examination I see that you need to replace multiple 'recordId' elements for presumably different landcodes which is certainly not trivial.
In that case I'd suggest you use an xslt with a lookup table. As I haven't used one of those myself I was curious so I fiddled around with some examples and came up with the following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://example.country"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- copy everything that is not country.recordId -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- create a lookup variable based on the table at the bottom -->
<xsl:key name="id-lookup" match="s:id" use="s:abbr"/>
<xsl:variable name="allrecordids" select="document('')/*/s:recordIds"/>
<!-- replace the country.recordIds -->
<xsl:template match="country.recordId">
<xsl:apply-templates select="$allrecordids">
<xsl:with-param name="curr-label" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="s:recordIds">
<xsl:param name="curr-label"/>
<country.recordId><xsl:value-of select="key('id-lookup', $curr-label)/s:nr"/></country.recordId>
</xsl:template>
<!-- the lookup table -->
<s:recordIds>
<s:id><s:abbr>AFG</s:abbr><s:nr>1234</s:nr></s:id>
<s:id><s:abbr>IND</s:abbr><s:nr>1235</s:nr></s:id>
</s:recordIds>
</xsl:stylesheet>
I made a big assumption here that the 'IND' and 'AFG' always results in the same number so hopefully this helps! At least it was fun :)
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
add a comment |
Interesting question. There are several routes available. I was going to suggest to pass the recordId as a variable to an xslt but upon careful examination I see that you need to replace multiple 'recordId' elements for presumably different landcodes which is certainly not trivial.
In that case I'd suggest you use an xslt with a lookup table. As I haven't used one of those myself I was curious so I fiddled around with some examples and came up with the following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://example.country"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- copy everything that is not country.recordId -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- create a lookup variable based on the table at the bottom -->
<xsl:key name="id-lookup" match="s:id" use="s:abbr"/>
<xsl:variable name="allrecordids" select="document('')/*/s:recordIds"/>
<!-- replace the country.recordIds -->
<xsl:template match="country.recordId">
<xsl:apply-templates select="$allrecordids">
<xsl:with-param name="curr-label" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="s:recordIds">
<xsl:param name="curr-label"/>
<country.recordId><xsl:value-of select="key('id-lookup', $curr-label)/s:nr"/></country.recordId>
</xsl:template>
<!-- the lookup table -->
<s:recordIds>
<s:id><s:abbr>AFG</s:abbr><s:nr>1234</s:nr></s:id>
<s:id><s:abbr>IND</s:abbr><s:nr>1235</s:nr></s:id>
</s:recordIds>
</xsl:stylesheet>
I made a big assumption here that the 'IND' and 'AFG' always results in the same number so hopefully this helps! At least it was fun :)
Interesting question. There are several routes available. I was going to suggest to pass the recordId as a variable to an xslt but upon careful examination I see that you need to replace multiple 'recordId' elements for presumably different landcodes which is certainly not trivial.
In that case I'd suggest you use an xslt with a lookup table. As I haven't used one of those myself I was curious so I fiddled around with some examples and came up with the following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://example.country"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- copy everything that is not country.recordId -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- create a lookup variable based on the table at the bottom -->
<xsl:key name="id-lookup" match="s:id" use="s:abbr"/>
<xsl:variable name="allrecordids" select="document('')/*/s:recordIds"/>
<!-- replace the country.recordIds -->
<xsl:template match="country.recordId">
<xsl:apply-templates select="$allrecordids">
<xsl:with-param name="curr-label" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="s:recordIds">
<xsl:param name="curr-label"/>
<country.recordId><xsl:value-of select="key('id-lookup', $curr-label)/s:nr"/></country.recordId>
</xsl:template>
<!-- the lookup table -->
<s:recordIds>
<s:id><s:abbr>AFG</s:abbr><s:nr>1234</s:nr></s:id>
<s:id><s:abbr>IND</s:abbr><s:nr>1235</s:nr></s:id>
</s:recordIds>
</xsl:stylesheet>
I made a big assumption here that the 'IND' and 'AFG' always results in the same number so hopefully this helps! At least it was fun :)
edited Nov 16 '18 at 16:55
answered Nov 16 '18 at 16:49
JanJan
52149
52149
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
add a comment |
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Thank You So much for the response but 'IND' and 'AFG' will change according to the System. Its like a DB Table which contains table.Country_Name as IND which is a unique Key and i need the table.ID from that table which should get replace.
– DhanaSekhar
Nov 19 '18 at 11:32
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
Is it possible to write a Select Query inside the XSLT ?
– DhanaSekhar
Nov 19 '18 at 11:37
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
I don't think it is possible to call a dblookup from within the xslt. Isn't it possible to add all the elements from the DB table to the xslt, assuming that this is a finite list that does not change very often?
– Jan
Nov 20 '18 at 10:24
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Nope.it's not about one table. i need to make it generic
– DhanaSekhar
Nov 26 '18 at 10:29
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
Okay, I have some ideas, will try to post an update later today.
– Jan
Nov 26 '18 at 12:16
add a comment |
As you indicated the solution above is not applicable to your specific use case, I came up with a different solution using foreach.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="translate_landcodes" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<foreach expression="//change">
<sequence>
<filter xpath="//country.recordId">
<then>
<property expression="//country.recordId" name="landcode" scope="default" type="STRING"/>
<sequence key="get_landnumber"/>
<enrich>
<source clone="true" property="landnumber" type="property"/>
<target xpath="//country.recordId"/>
</enrich>
</then>
</filter>
</sequence>
</foreach>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I ran into the following bug https://wso2.org/jira/browse/ESBJAVA-5227. Which is fixed in IE 6.20 and newer, but I solved it by moving the database call to a separate sequence:
<sequence name="get_landnumber" xmlns="http://ws.apache.org/ns/synapse">
<dblookup>
<connection>
<pool>
<dsName>jdbc/landcodes_db</dsName>
</pool>
</connection>
<statement>
<sql><![CDATA[select numbercode from translate where lettercode=?]]></sql>
<parameter expression="get-property('landcode')"
type="VARCHAR" xmlns:ns="http://org.apache.synapse/xsd"/>
<result column="numbercode" name="landnumber"/>
</statement>
</dblookup>
</sequence>
Note that you have to define the database connection in configuration/datasources.
add a comment |
As you indicated the solution above is not applicable to your specific use case, I came up with a different solution using foreach.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="translate_landcodes" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<foreach expression="//change">
<sequence>
<filter xpath="//country.recordId">
<then>
<property expression="//country.recordId" name="landcode" scope="default" type="STRING"/>
<sequence key="get_landnumber"/>
<enrich>
<source clone="true" property="landnumber" type="property"/>
<target xpath="//country.recordId"/>
</enrich>
</then>
</filter>
</sequence>
</foreach>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I ran into the following bug https://wso2.org/jira/browse/ESBJAVA-5227. Which is fixed in IE 6.20 and newer, but I solved it by moving the database call to a separate sequence:
<sequence name="get_landnumber" xmlns="http://ws.apache.org/ns/synapse">
<dblookup>
<connection>
<pool>
<dsName>jdbc/landcodes_db</dsName>
</pool>
</connection>
<statement>
<sql><![CDATA[select numbercode from translate where lettercode=?]]></sql>
<parameter expression="get-property('landcode')"
type="VARCHAR" xmlns:ns="http://org.apache.synapse/xsd"/>
<result column="numbercode" name="landnumber"/>
</statement>
</dblookup>
</sequence>
Note that you have to define the database connection in configuration/datasources.
add a comment |
As you indicated the solution above is not applicable to your specific use case, I came up with a different solution using foreach.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="translate_landcodes" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<foreach expression="//change">
<sequence>
<filter xpath="//country.recordId">
<then>
<property expression="//country.recordId" name="landcode" scope="default" type="STRING"/>
<sequence key="get_landnumber"/>
<enrich>
<source clone="true" property="landnumber" type="property"/>
<target xpath="//country.recordId"/>
</enrich>
</then>
</filter>
</sequence>
</foreach>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I ran into the following bug https://wso2.org/jira/browse/ESBJAVA-5227. Which is fixed in IE 6.20 and newer, but I solved it by moving the database call to a separate sequence:
<sequence name="get_landnumber" xmlns="http://ws.apache.org/ns/synapse">
<dblookup>
<connection>
<pool>
<dsName>jdbc/landcodes_db</dsName>
</pool>
</connection>
<statement>
<sql><![CDATA[select numbercode from translate where lettercode=?]]></sql>
<parameter expression="get-property('landcode')"
type="VARCHAR" xmlns:ns="http://org.apache.synapse/xsd"/>
<result column="numbercode" name="landnumber"/>
</statement>
</dblookup>
</sequence>
Note that you have to define the database connection in configuration/datasources.
As you indicated the solution above is not applicable to your specific use case, I came up with a different solution using foreach.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="translate_landcodes" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<foreach expression="//change">
<sequence>
<filter xpath="//country.recordId">
<then>
<property expression="//country.recordId" name="landcode" scope="default" type="STRING"/>
<sequence key="get_landnumber"/>
<enrich>
<source clone="true" property="landnumber" type="property"/>
<target xpath="//country.recordId"/>
</enrich>
</then>
</filter>
</sequence>
</foreach>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I ran into the following bug https://wso2.org/jira/browse/ESBJAVA-5227. Which is fixed in IE 6.20 and newer, but I solved it by moving the database call to a separate sequence:
<sequence name="get_landnumber" xmlns="http://ws.apache.org/ns/synapse">
<dblookup>
<connection>
<pool>
<dsName>jdbc/landcodes_db</dsName>
</pool>
</connection>
<statement>
<sql><![CDATA[select numbercode from translate where lettercode=?]]></sql>
<parameter expression="get-property('landcode')"
type="VARCHAR" xmlns:ns="http://org.apache.synapse/xsd"/>
<result column="numbercode" name="landnumber"/>
</statement>
</dblookup>
</sequence>
Note that you have to define the database connection in configuration/datasources.
edited Nov 27 '18 at 13:54
answered Nov 27 '18 at 12:06
JanJan
52149
52149
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335509%2fchange-inside-tag-values-or-node-values-of-xml-in-wso2-esb-using-any-script-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown