Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Grouping based on several values [Thread Next] Re: Grouping based on several valuesTo: NULL Date: 9/3/2006 9:26:00 PM
I think I figured it out! Here's a sanitized overview of what I did:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" version="1.0">
<xsl:output omit-xml-declaration="yes" version="1.0" method="xml" />
<xsl:key name="POKey" match="//LineItems/LineItem"
use="concat(@FulfillmentPartnerId,'_',@DeliveryAddressId,'_',@DeliveryMethodId)"
/>
<xsl:template match="/">
<PurchaseOrders>
<xsl:apply-templates select="*" />
</PurchaseOrders>
</xsl:template>
<xsl:template match="LineItem">
<xsl:variable name="nodeList" select="key('POKey',
concat(@FulfillmentPartnerId,'_',@DeliveryAddressId,'_',@DeliveryMethodId))"/>
<xsl:if test="generate-id($nodeList) = generate-id()">
<PurchaseOrder>
<xsl:attribute name="Id">
<xsl:value-of select="@Id" />
</xsl:attribute>
<xsl:attribute name="PartnerId">
<xsl:value-of select="@FulfillmentPartnerId" />
</xsl:attribute>
<xsl:attribute name="DeliveryMethodId">
<xsl:value-of select="@DeliveryMethodId" />
</xsl:attribute>
...
<xsl:element name="LineItems">
<xsl:apply-templates select="$nodeList" mode="innerGroup" />
</xsl:element>
<xsl:element name="DeliveryAddress">
<xsl:variable name="var:DeliveryAddressId"
select="@DeliveryAddressId" />
<xsl:apply-templates
select="../../Addresses/Address[@Id=$var:DeliveryAddressId]"
mode="innerGroup" />
</xsl:element>
...
</PurchaseOrder>
</xsl:if>
</xsl:template>
<xsl:template match="LineItem" mode="innerGroup">
<LineItem>
<xsl:attribute name="Id">
<xsl:value-of select="@Id" />
</xsl:attribute>
<xsl:attribute name="ProductId">
<xsl:value-of select="@ProductId" />
</xsl:attribute>
<!-- Using a BizTalk Server 2006 Extension Object -->
<xsl:variable name="var:v3"
select="ScriptNS0:RetrievePartnerProductId(string(@FulfillmentPartnerId) ,
string(@ProductId))" />
<xsl:attribute name="FulfillmentPartnerProductId">
<xsl:value-of select="$var:v3" />
</xsl:attribute>
<xsl:attribute name="Quantity">
<xsl:value-of select="@Quantity" />
</xsl:attribute>
<xsl:attribute name="UnitPrice">
<xsl:value-of select="@UnitPrice" />
</xsl:attribute>
...
</LineItem>
</xsl:template>
<xsl:template match="Address" mode="innerGroup">
<xsl:attribute name="FirstName">
<xsl:value-of select="@FirstName" />
</xsl:attribute>
...
</xsl:template>
</xsl:stylesheet>
Cheers,
Colin
"Colin Bowern" <colin.bowern@n...> wrote in message
news:utI4zM7zGHA.4648@T......
>I have a document where I want to group based on values several levels
>deep:
>
> <SalesOrder ...>
> <LineItems>
> <LineItem Id="1" DeliveryAddressId="Shipping" DeliveryMethodId="1"
> SupplierId="A" />
> <LineItem Id="2" DeliveryAddressId="Shipping" DeliveryMethodId="2"
> SupplierId="A" />
> <LineItem Id="3" DeliveryAddressId="Shipping" DeliveryMethodId="1"
> SupplierId="B" />
> <LineItem Id="4" DeliveryAddressId="Billing" DeliveryMethodId="2"
> SupplierId="B" />
> </LineItems>
> </SalesOrder>
>
> The above example should ideally end up in four purchase orders because of
> the combination of delivery address, method, and supplier. For example:
>
> <PurchaseOrder SupplierId="A" DeliveryMethod="1">
> <DeliveryAddress Id="Shipping" .. />
> <LineItems>
> <LineItem Id="1" />
> </PurchaseOrder>
>
> At this point I've gotten to a point where I can build out single
> line-item purchase orders based on this information. Ideally I want to
> aggregate based on the three values using XSLT.
>
> Has anyone seen this scenario before? Are there any good resources that
> you could share to help me understand what functions/approaches to take to
> resolve this?
>
> Thanks,
> Colin
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
