XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
ishpal singhSubject: Keeping track of position after sorting
Author: ishpal singh
Date: 07 Jun 2011 02:22 PM
Hi,

I've been trying to apply xsl to the result set returned by Analysis Service database.
The result set looks like the following...
<Axis name="Axis1">
<Tuples>
<Tuple>
<Member Hierarchy="[Org].[Class1]">
<UName>[Org].[Class1].&amp;[10629]</UName>
<Caption>Independent</Caption>
<LName>[Org].[Class1].[Ownership]</LName>
<LNum>2</LNum>
<DisplayInfo>65898</DisplayInfo>
<PARENT_UNIQUE_NAME>[Org].[Class1].&amp;[2]</PARENT_UNIQUE_NAME>
</Member>
</Tuple>
<Tuple>
<Member Hierarchy="[Org].[Class1]">
<UName>[Org].[Class1].&amp;[14331]</UName>
<Caption>A #5839</Caption>
<LName>[Org].[Class1].[Owner Region]</LName>
<LNum>3</LNum>
<DisplayInfo>65537</DisplayInfo>
<PARENT_UNIQUE_NAME>[Org].[Class1].&amp;[10629]</PARENT_UNIQUE_NAME>
</Member>
</Tuple>
....
</Axis>
<CellData>
<Cell CellOrdinal="0">
<FmtValue>Ownership</FmtValue>
</Cell>
<Cell CellOrdinal="1">
<ForeColor>0</ForeColor>
<FmtValue>73%</FmtValue>
</Cell>
<Cell CellOrdinal="2">
<ForeColor>0</ForeColor>
<FmtValue>68%</FmtValue>
</Cell>
<Cell CellOrdinal="3">
<ForeColor>0</ForeColor>
<FmtValue>70%</FmtValue>
</Cell>
<Cell CellOrdinal="4">
<ForeColor>0</ForeColor>
<FmtValue>59%</FmtValue>
</Cell>
<Cell CellOrdinal="5">
<FmtValue>Owner Region</FmtValue>
</Cell>
<Cell CellOrdinal="6">
<ForeColor>0</ForeColor>
<FmtValue>75%</FmtValue>
</Cell>
.....
</CellData>

Each Tuple above has a corresponding set of Cells in the CellData.
So, if the file is parsed sequentially, the relevant cells can be gathered using the position() of the Tuple.

However, if the Tuple is sorted using xsl-sort, LNum property, and iterated over using for-each, the position of the Tuples is now changed and so can not find the corresponding Cell for the Tuple.

How can I keep track of the Tuple ordinal based on UName, so that I can get to the relevant cell.
I have created a key for the UName as <xsl:key name="tuples-by-uName" match="/xa:root/xa:Axes/xa:Axis/xa:Tuples/xa:Tuple" use="xa:Member/xa:UName" />
<xsl:key name="tuples-by-parentUName" match="/xa:root/xa:Axes/xa:Axis/xa:Tuples/xa:Tuple" use="xa:Member/xa:PARENT_UNIQUE_NAME" />

And want to iterate over the tuples using something like the following.

<xsl:for-each select="key('tuples-by-parentUName', $thisQuestion/xa:Member/xa:UName)">
<xsl:sort data-type="number" select="xa:Member/xa:LNum" order="descending"/>

Here I need the original position of the Tuple so I can calculate the position of the Cell.

Have spent a lot of time, but can not figure this one out.

Please help!

-Ishpal

Postnext
Ivan PedruzziSubject: Keeping track of position after sorting
Author: Ivan Pedruzzi
Date: 08 Jun 2011 01:23 AM


You don't need a key to calculate the index

<xsl:variable name="pos" select="count(preceding-sibling::Tuple) + 1"/>

Then you can use $pos to access the cell node by position

CellData/Cell[$pos]

Hope this helps
Ivan

Posttop
ishpal singhSubject: Keeping track of position after sorting
Author: ishpal singh
Date: 08 Jun 2011 09:25 AM
Thanks for the reply.
This should solve my problem.

cheers,
Ishpal

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.