xsl-list
[Top] [All Lists]

[xsl] Setting Attributes from Key value

2007-08-21 09:27:03

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[(_at_)ColIndex] must be set to the zero-offset index of the
Attribute-Format element within the Attribute-Format-Collection element.

So far, I've set up a key to hold the Attribute-Format elements, keyed
on the Key attribute, and I've managed to use that to identify those
Grouping elements that have valid Attributre-Format Key's.

What I have not been able to do so far is to fill out the ColIndex
attribute of the new Grouping element with  the offset of the
corresponding Attribute-Format element in the
Attribute-Format-Collection element.  Here's what I have so far.  I've
included both unsuccessful attempts at using xsl:value-of to retrieve
the right offset value with which to populate the ColIndex.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>

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

  <xsl:key name="attribute-format-by-key" match="Attribute-Format"
use="@Key" />

  <xsl:template match="//Grouping-Collection/Grouping">
    <xsl:copy select=".">
      <xsl:if test="key('attribute-format-by-key', @Key)" >
        <xsl:attribute name="ColIndex">
          <xsl:value-of select="key('attribute-format-by-key',
@Key)[(_at_)ColIndex]" />
          <xsl:value-of
select="/Report/View-Category/Attribute-Format-Collection/Attribute-Form
at[(_at_)Key=@Key][(_at_)ColIndex]" />
        </xsl:attribute>
      </xsl:if>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Anybody have any ideas about how to approach this problem?

Thanks.

-Eric.





Eric D. Berg
Lehman Brothers
Fixed Income Research
745 7th Avenue, 15th floor
New York, NY 10019
Phone +1 212 526 8118


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - -

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.



--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>