Subject: [xsl] Setting Attributes from Key value From: "Berg, Eric" <eric.berg@xxxxxxxxxx> Date: Tue, 21 Aug 2007 12:25:50 -0400 |
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. 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)[@ColIndex]" /> <xsl:value-of select="/Report/View-Category/Attribute-Format-Collection/Attribute-Form at[@Key=@Key][@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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: "xstlApplyOneTemplate:key, John Escott | Thread | Re: [xsl] Setting Attributes from K, David Carlisle |
Re: [xsl] Selecting First Direct Si, David Carlisle | Date | Re: [xsl] Setting Attributes from K, David Carlisle |
Month |