Subject: Re: Mapping from two sources (~ inner join in DB)
From: sudheshna iyer <sudheshnaiyer@xxxxxxxxx>
Date: Sun, 3 Oct 2010 14:43:54 -0700 (PDT)
|
Thank you Ken. I see that "key" is doing the trick of inner join replacing
>xsl:if>
--- On Sun, 10/3/10, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>
wrote:
> From: G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>
> Subject: Re:
Mapping from two sources (~ inner join in DB)
> To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Sunday, October 3, 2010, 3:26 PM
> At
2010-10-03 11:56 -0700, sudheshna
> iyer wrote:
> > For the below question, I
got the answers from you
> using <xsl:for-each-group>. But my version of XSLT
is
> not supporting xsl:for-each-group.
>
> Then it must be XSLT 1.0.
>
> >
Is there a different way of implementing this?
>
> Please find an XSLT 1.0
solution below that generates the
> output you specify.
>
> I hope this
helps.
>
> . . . . . . . . Ken
>
> p.s. Which order/order-response
vocabularies are you
> using? Have you considered using the OASIS Universal
>
Business Language (UBL) for such business documents?
>
>
http://docs.oasis-open.org/ubl/os-UBL-2.0/UBL-2.0.html
>
http://docs.oasis-open.org/ubl/UBL-2.0-update.html
>
> ~/t/ftemp $ cat
input1.xml
> <?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>
> ~/t/ftemp $ cat input2.xml
> <?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>
> ~/t/ftemp $ cat
innerjoin.xsl
> <?xml version="1.0" encoding="US-ASCII"?>
> <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
>
version="1.0">
>
> <xsl:output indent="yes"/>
>
> <xsl:key
name="order-line-by-number" match="*[OLN]"
> use="OLN"/>
>
> <xsl:template
match="/">
> <xsl:variable name="input1"
> select="document('input1.xml')"/>
> <xsl:variable name="input2"
> select="document('input2.xml')"/>
>
>
<OrderResponse>
> <!--walk each order line-->
> <xsl:for-each
>
select="$input1/Order/OrderLine">
> <xsl:variable name="input1line"
>
select="."/>
> <!--change context to the other
> file-->
>
<xsl:for-each select="$input2">
> <!--act only on the lines of
> equal
line number-->
> <xsl:for-each
>
select="key('order-line-by-number',$input1line/OLN)">
> <!--join the
> information from both files-->
> <Oline>
>
<xsl:copy-of
> select="OLN"/>
> <xsl:copy-of
>
select="$input1line/Fname"/>
> <xsl:copy-of
> select="ID"/>
>
</Oline>
> </xsl:for-each>
> </xsl:for-each>
>
</xsl:for-each>
> </OrderResponse>
> </xsl:template>
>
> </xsl:stylesheet>
> ~/t/ftemp $ xslt innerjoin.xsl innerjoin.xsl
> <?xml version="1.0"
encoding="utf-8"?>
> <OrderResponse>
> <Oline>
> <OLN>1</OLN>
>
<Fname>aa</Fname>
> <ID>123</ID>
> </Oline>
> <Oline>
>
<OLN>2</OLN>
> <Fname>bb</Fname>
> <ID>324</ID>
> </Oline>
>
</OrderResponse>~/t/ftemp $
>
>
> > <?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>
>
>
> --
>
XSLT/XQuery training: after http://XMLPrague.cz 2011-03-28/04-01
> Vote for
your XML training: http://www.CraneSoftwrights.com/s/i/
> Crane Softwrights
Ltd. http://www.CraneSoftwrights.com/s/
> G. Ken Holman
>
mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> Male Cancer Awareness Nov'07
http://www.CraneSoftwrights.com/s/bc
> Legal business disclaimers:
http://www.CraneSoftwrights.com/legal
>
>
>
--~------------------------------------------------------------------
>
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>
> --~--
|