[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: RE: Join XMLs with XLST with ralative data

Subject: RE: RE: Join XMLs with XLST with ralative data
From: Americo Albuquerque <melinor@xxxxxxx>
Date: Mon, 9 Jun 2003 16:31:07 +0100
xslt for each join
Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Mangesh Kakade
> Sent: Monday, June 09, 2003 11:29 AM
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:RE:  Join XMLs with XLST with ralative data 
> 
> 
> Hi Jarno and all Gurus ,
> Thanks for the reply ...earlier i was in digest list
> now i am in daily-list..
> I have modified my xslt as suggested but still it is
> not working properly so the out put with the two xml s
> i.e.
> 22.xml 
> <STKAVAILABLE>
> 	<STKMAST Alias="01" STKCODE="31" STKDESC="FANTA ">
> 		<STKDESC IndexID="5017"/>
> 	</STKMAST>
> 	<STKMAST Alias="01" STKCODE="30" STKDESC="PEPSI">
> 		<STKDESC IndexID="5017"/>
> 	</STKMAST>
> ....
> </STKAVAILABLE>
> buy22.xml
> <buyermaster>
> 	<name id="a001" deptid="01">
> 		<bstkcode>31</bstkcode>
> 	</name>
> 	<name id="a010">
> 		<bstkcode>40</bstkcode>
> 	</name>
> 	<name id="a003" deptid="10">
> 		<bstkcode>31</bstkcode>
> 		<bstkcode>20</bstkcode>
> 	</name>
> </buyermaster>
> 
> And out put I want is ....
> < tran>
> 	<stock>
> 		<stockcode>31</stockcode>
> 		<name id="a001" deptid="01">
> 		<name id="a003" deptid="10">
> 	</stock>
> 	<stock>
> 		<stockcode>30</stockcode>
> <name id="a010">
> 	</stock>
> ...and so on if stock code from 22.xml matches
> bstkcode from buy22.xml
> </tran>

(...)

Try this:
 <xsl:template match="STKAVAILABLE">
  <tran>
   <xsl:apply-templates/>
  </tran>
 </xsl:template>
 
 <xsl:template match="STKMAST">
  <stock>
   <stockcode><xsl:value-of select="@STKCODE"/></stockcode>
   <xsl:apply-templates
select="document('buy22.xml')/buyermaster/name[bstkcode=current()/@STKCODE]"
/>
  </stock>
 </xsl:template>
 
 <xsl:template match="name">
  <xsl:copy>
   <xsl:copy-of select="@*"/>
  </xsl:copy>
 </xsl:template>


When applied to 22.xml produces the expected result

> so based on suggestion I have modified my xslt to : 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:key name="rows-bstkcode" match="name"
> use="bstkcode"/>
> 	<xsl:variable name="x_22"
> select="document('22.xml')"/>
> 	<xsl:variable name="buy22"
> select="document('buy22.xml')"/>
> 	<xsl:template match="/">
> 		<tran>
> 		     <xsl:for-each
> select="$x_22/STKAVAILABLE/STKMAST">
> 		      <xsl:variable name="STKCODE1"
> select="@STKCODE"/>
> 			<xsl:for-each select="$buy22/buyermaster">
> 			   <stock>
> 		                  <stockcode> <xsl:value-of 
> select="$STKCODE1" /></stockcode>
> 			      <xsl:for-each
> select="key('rows-bstkcode',$STKCODE1)">
> 				      <xsl:copy>		
> 								
> 	<xsl:copy-of
> select="bstkcode"/>

Here you probably want <xsl:copy-of select="@*"/> instead.

> 				       </xsl:copy>
>                       		       </xsl:for-each>
> 		               </stock>
> 			 </xsl:for-each>
> 		      </xsl:for-each>
> 		</tran>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> but out put I am getting still is :
> <?xml version="1.0" encoding="UTF-8" ?> 
> <tran>
> <stock>
>  <stockcode>31</stockcode> 
>  	 </stock>
> <stock>
>  		 <stockcode>30</stockcode> 
>  </stock>
>  <stock>
>   		<stockcode>32</stockcode> 
>  	 </stock>
> </tran>
> 
(...)

Your code should work, it worked with msxml3



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.