Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Grouping based on several values

From: "Colin Bowern" <colin.bowern@------.-----------------.--->
To: 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
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent