[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Setting Attributes from Key value..solved

Subject: RE: Setting Attributes from Key value..solved
From: "Berg, Eric" <eric.berg@xxxxxxxxxx>
Date: Wed, 22 Aug 2007 12:00:51 -0400
 RE: Setting Attributes from Key value..solved
Thanks to David Carlisle for some good info that helped me solve this

Here's the stylesheet that addresses the problem for posterity.  The
improvements to the initial post are in a few areas:

- Using the count(key('attribute-format-by-key',
@Key)/preceding-sibling::*) to get the index value of the
Attribute-Format element in the Attribute-Format-Collection.
- Using an empty template to suppress output of Grouping elements which
had no corresponding Attribute-Format (using their Key attributes to
refer from Grouping to Attribute-Format)
- Now uses copy-of to build out Grouping with matching Key

  <!-- Default copy -->
  <xsl:template match="@*|node()">
      <xsl:apply-templates select="@*|node()"/>

  <!-- Create the lookup for Attribute-Format elements, keyed on Key -->
  <xsl:key name="attribute-format-by-key" match="Attribute-Format"
use="@Key" />

  <!-- Template to delete Groupings that don't have matching
     Attribute-Format elements -->
  <xsl:template match="Grouping[not(key('attribute-format-by-key',
@Key))]" />

  <!-- Match the Groupings that have Attriute-Format matches and
     rebuild then with the correct ColIndex values -->
  <xsl:template match="Grouping">
      <xsl:copy-of select="@*" />
      <xsl:attribute name="ColIndex">
        <xsl:value-of select="count(key('attribute-format-by-key',
@Key)/preceding-sibling::*)" />

Thanks for your help.


> _____________________________________________
> From: 	Berg, Eric
> Sent:	Tuesday, August 21, 2007 12:26 PM
> To:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:	Setting Attributes from Key value
> Hey, folks.
> I've got a bunch of XML that I need to transform, and it seems a
> little tricky to me.  Let me lay out the problem.
> I have a bunch of Attribute-Format elements in an
> Attribute-FormatCollection.  Each one has a Key attribute.
> These Attribute-Format elements are referred to by a bunch of Grouping
> elements contained within a Grouping Collection element. The Key
> attribute in the Grouping elements contains the same value as the Key
> attribute in the Attribute-Format element to which it is referring.
> An example snippet:
>       <Attribute-Format-Collection>
>          <Attribute-Format Key="Cusip"/>
>          <Attribute-Format Key="ModOADuration" />
>          <Attribute-Format Key="PriceMktConv"/>
>       </Attribute-Format-Collection>
>       <Grouping-Collection>
>          <Grouping ColIndex="0" Index="1" Is-Grouped="0"
> Key="BadGarbageMojo"/>
>          <Grouping ColIndex="2" Index="0" Is-Grouped="0"
> Key="ModOADuration" />
>          <Grouping ColIndex="3" Index="3" Is-Grouped="0"
> Key="OtherUselessJunk" />
>          <Grouping ColIndex="3" Index="2" Is-Grouped="0"
> Key="PriceMktConv" />
>       </Grouping-Collection>
> There are two things I need to do based on the results of matching the
> Grouping with the Attribute-Format.
> 1) If there is no matching Attribute-Format for the Grouping, the
> Grouping element should simply be deleted.
> 2) If there is a corresponding Attribute-Format match for the
> Grouping, the Grouping[@ColIndex] must be set to the zero-offset index
> of the Attribute-Format element within the Attribute-Format-Collection
> element.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -

This message is intended only for the personal and confidential use of the
designated recipient(s) named above.  If you are not the intended recipient of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited.  This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be
secure or error-free.  Therefore, we do not represent that this information is
complete or accurate and it should not be relied upon as such.  All
information is subject to change without notice.

IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within
this communication (including any attachments) is not intended or written to
be used and cannot be used for the purpose of (i) avoiding U.S. tax related
penalties or (ii) promoting, marketing or recommending to another party any
transaction or matter addressed herein.

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.