Xslt loop through different nodes and combine in BizTalk map -
i want compare 2 records in single xml file , fetch matching records. (note: not able change inputschema)
the inputrequest1 contains identifiers (id , idscheme) , want compare inputrequest2 contains multiple products , corresponding identifiers (id , idscheme) , login detials (id , idscheme - login). should compare inputrequest1 inputrequest2 nodes , extract matching product details form output. output should contain login , id details shown in example below.
sample xml:
<ns0:root xmlns:ns0="http://schemas.microsoft.com/biztalk/2003/aggschema"> <inputmessagepart_0> <ns1:inputrequest1 xmlns:ns1="http://myclient/schema/5.0.0/"> <ns1:identifier> <ns1:id>123456</ns1:id> <ns1:idscheme>abc</ns1:idscheme> </ns1:identifier> <ns1:identifier> <ns1:id>654321</ns1:id> <ns1:idscheme>cba</ns1:idscheme> </ns1:identifier> <ns1:identifier> <ns1:id>2356152</ns1:id> <ns1:idscheme>zzz</ns1:idscheme> </ns1:identifier> </ns1:inputrequest1> </inputmessagepart_0> <inputmessagepart_1> <ns1:inputrequest2 xmlns:ns1="http://myclient/schema/5.0.0/"> <ns1:products> <ns1:profilecontext> <ns1:loginid> <ns1:id>login123</ns1:id> <ns1:idscheme>userid</ns1:idscheme> </ns1:loginid> </ns1:profilecontext> <ns1:productdetails> <ns1:productidentifier> <ns1:id>123456</ns1:id> <ns1:idscheme>abc</ns1:idscheme> </ns1:productidentifier> </ns1:productdetails> </ns1:products> <ns1:products> <ns1:profilecontext> <ns1:memberidentifier> <ns1:id>login789</ns1:id> <ns1:idscheme>usertid</ns1:idscheme> </ns1:memberidentifier> </ns1:profilecontext> <ns1:productdetails> <ns1:productidentifier> <ns1:id>9876543</ns1:id> <ns1:idscheme>def</ns1:idscheme> </ns1:productidentifier> </ns1:productdetails> </ns1:products> <ns1:products> <ns1:profilecontext> <ns1:memberidentifier> <ns1:id>login456</ns1:id> <ns1:idscheme>usertid</ns1:idscheme> </ns1:memberidentifier> </ns1:profilecontext> <ns1:productdetails> <ns1:productidentifier> <ns1:id>456789</ns1:id> <ns1:idscheme>cba</ns1:idscheme> </ns1:productidentifier> </ns1:productdetails> </ns1:products> </ns1:inputrequest2> </inputmessagepart_1> </ns0:root>
i want output be:
<ns1:outputrequest xmlns:ns1="http://myclientoutput/schema/5.0.0/"> <ns1:identifier> <ns1:id>login123</ns1:id> <ns1:idscheme>userid</ns1:idscheme> </ns1:identifier> <ns1:identifier> <ns1:id>123456</ns1:id> <ns1:idscheme>abc</ns1:idscheme> </ns1:identifier> <ns1:identifier> <ns1:id>login456</ns1:id> <ns1:idscheme>userid</ns1:idscheme> </ns1:identifier> <ns1:identifier> <ns1:id>654321</ns1:id> <ns1:idscheme>cba</ns1:idscheme> </ns1:identifier> </ns1:outputrequest>
can please me in xslt transformation? thanks.
thanks responses.
initially trying use xpath in for-each , since scope in inner for-each different, unable access variables. but, using variables (reading entire node variable), able achieve wanted. below code got me result.
<ns0:outputrequest> <xsl:variable name="msg1" select="inputmessagepart_0/ns0:inputrequest1/ns0:identifier"/> <xsl:variable name="msg2" select="inputmessagepart_1/ns0:inputrequest2/ns0:products"/> <xsl:for-each select="$msg1"> <xsl:variable name="requestid" select="ns0:identifier/text()" /> <xsl:variable name="requestidscheme" select="ns0:identifierscheme/text()" /> <xsl:for-each select="$msg2"> <xsl:variable name="loginid" select="ns0:profilecontext/ns0:loginid/ns0:id/text()"/> <xsl:variable name="loginidscheme" select="ns0:profilecontext/ns0:loginid/ns0:idscheme/text()"/> <xsl:variable name="responseid" select="ns0:productdetails/ns0:productidentifier/ns0:id/text()" /> <xsl:variable name="responseidscheme" select="ns0:productdetails/ns0:productidentifier/ns0:idscheme/text()" /> <xsl:if test="$requestid = $responseid , $requestidscheme = $responseidscheme"> <ns0:identifier> <ns0:id> <xsl:value-of select="$loginid" /> </ns0:id> <ns0:idscheme> <xsl:value-of select="$loginidscheme" /> </ns0:idscheme> </ns0:identifier> <ns0:identifier> <ns0:id> <xsl:value-of select="$responseid" /> </ns0:id> <ns0:idscheme> <xsl:value-of select="$responseidscheme" /> </ns0:idscheme> </ns0:identifier> </xsl:if> </xsl:for-each> </xsl:if> </ns0:outputrequest>
thanks again.
Comments
Post a Comment