[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Mapping from two sources


Subject: Re: [xsl] Mapping from two sources
From: sudheshna iyer <sudheshnaiyer@xxxxxxxxx>
Date: Sun, 3 Oct 2010 05:04:05 -0700 (PDT)

Amazing Martin!  I replaced $doc2//POOrderLine with $doc2//POOrderLine and it
worked!

Thank you.

--- On Sun, 10/3/10, Martin Honnen <Martin.Honnen@xxxxxx>
wrote:

> From: Martin Honnen <Martin.Honnen@xxxxxx>
> Subject: Re: [xsl]
Mapping from two sources
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Sunday,
October 3, 2010, 7:49 AM
> sudheshna iyer wrote:
> > Thank you for your
answers. 
> > But the solution returns only elements from Doc1, I
> need
element of Doc2 if
> > doc1.OLN = doc2.OLN
> > ========
> > Problem
> > 
> > I
need to have two sources:
> > 
> > input1 and input2. 
> > input1:
> > <?xml
version="1.0" encoding="ISO-8859-1"?>
> > <Order>
> >     <OrderLine>
> >    
   
>     <OLN>1</OLN>
> >        
>     <Fname>aa</Fname>
> >    
</OrderLine>
> >     <OrderLine>
> >        
>     <OLN>2</OLN>
> >        
>
    <Fname>bb</Fname>
> >    
> </OrderLine>    
> > </Order>
> > 
> > 
> >
input2:
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <POOrder>
> >    
<POOrderLine>
> >        
>     <OLN>1</OLN>
> >        
>     <ID>123</ID>
>
>        
>     <LName>aa</LName>
> >     </POOrderLine>
> >     <POOrderLine>
> >        
>     <OLN>2</OLN>
> >        
>     <ID>324</ID>
> >        
>
    <LName>bb</LName>
> >    
> </POOrderLine>    
> >     <POOrderLine>
> >
       
>     <OLN>3</OLN>
> >        
>     <ID>456</ID>
> >        
>    
<LName>bb</LName>
> >    
> </POOrderLine>    
> > </POOrder>
> > 
> > I need
the output from both sources combined. Please
> note that first two elements
are coming from input1 and
> thrid element is from input2. What is the optimal
way of
> doing this?
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> >
<OrderResponse>
> >     <Oline>
> >        
> <OLN>1</OLN>
> >        
>
<Fname>aa</Fname>
> >        
> <ID>123</ID>
> >     </Oline>
> >     <Oline>
> >        
> <OLN>2</OLN>
> >        
> <Fname>bb</Fname>
> >        
>
<ID>324</ID>
> >     </Oline>
> > </OrderResponse>
> > =====
> > 
> > Solution
proposed:
> > 
> > <xsl:for-each-group select="$doc1//OrderLine,
>
$doc2//POOrderline"
> > group-by="OLN">
> > <Oline>
> > <OLN><xsl:value-of
>
select="current-grouping-key()"></OLN>
> > <xsl:copy-of
select="current-group()/(FName,
> ID)"/>
> > </Oline>
> >
</xsl:for-each-group>
> 
> It might simply be a problem of use the same
spelling and
> case for element names in the input and the stylesheet (i.e.
>
POOrderLine and not POOrderline) so try
> 
> <xsl:stylesheet
>   version="2.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   exclude-result-prefixes="xs">
> 
>   <xsl:output method="xml" indent="yes"/>
> 
>   <xsl:variable
name="doc1" select="/"/>
> 
>   <xsl:param name="doc2Url" as="xs:string"
>
select="'input2.xml'"/>
>   <xsl:variable name="doc2"
>
select="doc($doc2Url)"/>
> 
>   <xsl:template match="/">
>     <OrderResponse>
>       <xsl:for-each-group
> select="$doc1//OrderLine, $doc2//POOrderLine"
>
      group-by="OLN">
>         <Oline>
>          
> <OLN><xsl:value-of
>
select="current-grouping-key()"/></OLN>
>           <xsl:copy-of
>
select="current-group()/(Fname, ID)"/>
>         </Oline>
>      
</xsl:for-each-group>
>     </OrderResponse>
>   </xsl:template>
> 
>
</xsl:stylesheet>
> 
> and then with your above samples you get
> 
>
<OrderResponse>
>    <Oline>
>       <OLN>1</OLN>
>       <Fname>aa</Fname>
>
      <ID>123</ID>
>    </Oline>
>    <Oline>
>       <OLN>2</OLN>
>      
<Fname>bb</Fname>
>       <ID>324</ID>
>    </Oline>
>    <Oline>
>      
<OLN>3</OLN>
>       <ID>456</ID>
>    </Oline>
> </OrderResponse>
> 
> -- 
>
    Martin Honnen
>     http://msmvps.com/blogs/martin_honnen/
> 
>
--~------------------------------------------------------------------
>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --~--


Current Thread