| Author |
Mapping Help Needed!
|
|
| Jeff Lynch 2005-02-26, 2:50 am |
| I have an inbound document as shown below.
<Orders>
<Order>
<Header OrderNo="123"></Header>
<Line Item="ABC" Date="02-25-2005"></Line>
<Line Item="DEF" Date="02-26-2005"></Line>
<Line Item="YXZ" Date="02-26-2005"></Line>
<Footer NoLines="3"></Footer>
</Order>
</Orders>
I need help creating the map to transform to this if possible:
<Orders>
<Order>
<Header OrderNo="123"></Header>
<Line Item="ABC" Date="02-25-2005"></Line>
<Footer NoLines="1"></Footer>
</Order>
<Order>
<Header OrderNo="123"></Header>
<Line Item="DEF" Date="02-26-2005"></Line>
<Line Item="YXZ" Date="02-26-2005"></Line>
<Footer NoLines="2"></Footer>
</Order>
</Orders>
Basically, I need to split the single <Order></Order> into multiple
<Order></Order> with the same <Header> but with the <Line> items grouped
together by "Date". The schema
--
Jeff Lynch
"A BizTalk Enthusiast"
http://codebetter.com/blogs/jeff.lynch/
| |
| Sasidhar Parvatham 2005-02-26, 8:46 pm |
| Hi Jeff,
Hope this is what you asked for.... this produces the exact result you
showed below minus the count.... I am lazy to finish that one.... Please
dont tell me that this is not what you are looking for... I spent half an
hour ... Hope this atleast helps you get an idea....... If you have
Xselerator try that for testing purposes....A useful link is ...
http://www.jenitennison.com/xslt/grouping/index.html
<?xml version="1.0" encoding="UTF-8" ?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="Orders">
<xsl:call-template name="Orders-by-date" />
</xsl:template>
<xsl:key name="group-by-date" match="Orders/Order/Line" use="@Date" />
<xsl:template name="Orders-by-date">
<xsl:element name="Orders">
<xsl:variable name="unique_dates"
select="//Orders/Order/Line[generate-id(.) =
generate-id(key('group-by-date', @Date))]" />
<xsl:for-each select="$unique_dates">
<xsl:sort order="ascending" select="./@Date"/>
<xsl:variable name="thisDate" select="./@Date" />
<xsl:element name="Order">
<xsl:element name="Header">
<xsl:attribute name="OrderNo">
<xsl:value-of select="../Header/@OrderNo" />
</xsl:attribute>
</xsl:element>
<xsl:for-each select="//Orders/Order/Line">
<xsl:if test="@Date = $thisDate">
<xsl:element name="Line">
<xsl:attribute name="Item">
<xsl:value-of select="string(./@Item)" />
</xsl:attribute>
<xsl:attribute name="Date">
<xsl:value-of select="string(./@Date)" />
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</stylesheet>
--
Sasidhar
http://bizstop.blogspot.com/
"Jeff Lynch" <jeff.lynch@houston-lynch.com> wrote in message
news:evpeLI8GFHA.432@TK2MSFTNGP09.phx.gbl...
> I have an inbound document as shown below.
>
> <Orders>
> <Order>
> <Header OrderNo="123"></Header>
> <Line Item="ABC" Date="02-25-2005"></Line>
> <Line Item="DEF" Date="02-26-2005"></Line>
> <Line Item="YXZ" Date="02-26-2005"></Line>
> <Footer NoLines="3"></Footer>
> </Order>
> </Orders>
>
> I need help creating the map to transform to this if possible:
>
> <Orders>
> <Order>
> <Header OrderNo="123"></Header>
> <Line Item="ABC" Date="02-25-2005"></Line>
> <Footer NoLines="1"></Footer>
> </Order>
> <Order>
> <Header OrderNo="123"></Header>
> <Line Item="DEF" Date="02-26-2005"></Line>
> <Line Item="YXZ" Date="02-26-2005"></Line>
> <Footer NoLines="2"></Footer>
> </Order>
> </Orders>
>
> Basically, I need to split the single <Order></Order> into multiple
> <Order></Order> with the same <Header> but with the <Line> items grouped
> together by "Date". The schema
>
> --
> Jeff Lynch
> "A BizTalk Enthusiast"
> http://codebetter.com/blogs/jeff.lynch/
>
>
>
| |
| Sasidhar Parvatham 2005-02-26, 8:46 pm |
| I would advice to use a script for incrementing counter for your NoOfLines
footer. Its easy that way.
--
Sasidhar
http://bizstop.blogspot.com/
"Sasidhar Parvatham" <sasidhar.parvatham@gmail.com> wrote in message
news:Ofaov2GHFHA.4060@TK2MSFTNGP14.phx.gbl...
> Hi Jeff,
>
> Hope this is what you asked for.... this produces the exact result you
> showed below minus the count.... I am lazy to finish that one.... Please
> dont tell me that this is not what you are looking for... I spent half an
> hour ... Hope this atleast helps you get an idea....... If you have
> Xselerator try that for testing purposes....A useful link is ...
>
> http://www.jenitennison.com/xslt/grouping/index.html
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt">
> <xsl:strip-space elements="*" />
> <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
> <xsl:template match="Orders">
> <xsl:call-template name="Orders-by-date" />
> </xsl:template>
> <xsl:key name="group-by-date" match="Orders/Order/Line" use="@Date" />
> <xsl:template name="Orders-by-date">
> <xsl:element name="Orders">
> <xsl:variable name="unique_dates"
> select="//Orders/Order/Line[generate-id(.) =
> generate-id(key('group-by-date', @Date))]" />
> <xsl:for-each select="$unique_dates">
> <xsl:sort order="ascending" select="./@Date"/>
> <xsl:variable name="thisDate" select="./@Date" />
> <xsl:element name="Order">
> <xsl:element name="Header">
> <xsl:attribute name="OrderNo">
> <xsl:value-of select="../Header/@OrderNo" />
> </xsl:attribute>
> </xsl:element>
> <xsl:for-each select="//Orders/Order/Line">
> <xsl:if test="@Date = $thisDate">
> <xsl:element name="Line">
> <xsl:attribute name="Item">
> <xsl:value-of select="string(./@Item)" />
> </xsl:attribute>
> <xsl:attribute name="Date">
> <xsl:value-of select="string(./@Date)" />
> </xsl:attribute>
> </xsl:element>
> </xsl:if>
> </xsl:for-each>
> </xsl:element>
> </xsl:for-each>
> </xsl:element>
> </xsl:template>
> </stylesheet>
>
>
> --
> Sasidhar
> http://bizstop.blogspot.com/
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> "Jeff Lynch" <jeff.lynch@houston-lynch.com> wrote in message
> news:evpeLI8GFHA.432@TK2MSFTNGP09.phx.gbl...
>
>
| |
| Jeff Lynch 2005-02-27, 5:52 pm |
| Thanks for the assistance. It works great!
--
Jeff Lynch
"A BizTalk Enthusiast"
http://codebetter.com/blogs/jeff.lynch/
"Sasidhar Parvatham" <sasidhar.parvatham@gmail.com> wrote in message
news:OPG%23K9GHFHA.2356@TK2MSFTNGP12.phx.gbl...
>I would advice to use a script for incrementing counter for your NoOfLines
> footer. Its easy that way.
>
> --
> Sasidhar
> http://bizstop.blogspot.com/
>
>
>
> "Sasidhar Parvatham" <sasidhar.parvatham@gmail.com> wrote in message
> news:Ofaov2GHFHA.4060@TK2MSFTNGP14.phx.gbl...
>
>
|
|
|
|