2011-06-07 177 views
1

我一直在尝试将xsl应用于Analysis Service数据库返回的结果集。 结果集看起来如下...排序后跟踪位置

<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> 
    .... 
    </Tuples> 
</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> 

上述每个元组具有相应的一组在CellData细胞。 因此,如果文件被顺序解析,可以使用Tuple的position()来收集相关的单元格。但是,如果元组使用xsl-sort,LNum属性进行排序,并且使用for-each进行迭代,则元组的位置现在会更改,因此无法找到Tuple的相应单元格。

我该如何跟踪基于UName的元组序号,以便我可以到达相关单元格。
我已经创造了UNAME作为重点

<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" /> 

而且要遍历使用像下面这样的元组。

<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"/> 

这里我需要Tuple的原始位置,所以我可以计算Cell的位置。

花了很多时间,但无法弄清楚这一点。

+0

为什么'元组,byparentUName'被 “询问” 用'UName'? – 2011-06-07 21:13:36

回答

1

xsl:for-each

<xsl:variable name="originalPosition" select="count(preceding::xa:Tuple) + 1"/> 

<xsl:variable name="originalPosition"> 
    <xsl:number count="xa:Tuple" level="any"/> 
</xsl:variable>