[Home] [By Thread] [By Date] [Recent Entries]
I need to transform a file of random-order complex items into an ordered
file. I tried using 'for-each-group' nested, but failed to get the results I
wanted
As I said, in the input file, the items are random and an item may occur more than once and have <SomeData> elements with different contents - both <SomeData> elements need to be preserved in the output file. The <Items> are ordered by <Heading>, then sequentially by the three <SubDivX> elements, and finally by <SomeData>. Everything sorts as strings. I have been thinking about something like: <xsl:template match="List> <xsl:for-each-group select="Item" group-by="concat(Heading,SubDiv1,SubDiv2,SubDiv3) " collation="{$sorting-collation}"> <xsl:sort select="current-grouping-key()" collation="{$sorting-collation}"/> <xsl:for-each select="current-group()"> <xsl:sort select="SomeData" collation="{$sorting-collation}"/> -----but get lost in here---- </xsl:for-each> </xsl:for-each-group> </xsl:template> Am I close? I am missing some key concept about working with node sets and would appreciate any help. Oh, each of Heading, and the SubDivX elements have four attributes significant to the sorting. I think I can just substitute something like this SubDivX,SubDivX/@scott,SubDivX/@scott-number,SubDivX/@pofis,SubDivX/@pofis-number for each SubDivX and the Heading in the final version. Or is there an easier way to say that? Thanks, Mark Output file (ordered and consolidated)
<List>
<Item>
<Heading>Bonn</Heading>
<SubDiv1>Avenue</SubDiv1>
<SubDiv2>Crosswalks</SubDiv2>
<SubDiv3>Dangerous</SubDiv3>
<SomeData></SomeData>
</Item>
<Item >
<Heading>Prague</Heading>
<SomeData>1</SomeData> <----- Consolidated
<SomeData>2</SomeData>
</Item>
<Item>
<Heading>Prague</Heading>
<SubDiv1>Avenues</SubDiv1>
<SomeData></SomeData>
</Item>
<Item>
<Heading>Prague</Heading>
<SubDiv1>Avenues</SubDiv1>
<SubDiv2>Crosswalks</SubDiv2>
< SomeData></SomeData>
</Item>
<Item>
<Heading>Prague</Heading>
<SubDiv1>Avenue</SubDiv1>
<SubDiv2>Crosswalks</SubDiv2>
<SubDiv3>Dangerous</SubDiv3>
<SomeData></SomeData>
</Item>
<Item>
<Heading>Prague</Heading>
< SubDiv1>Streets</SubDiv1>
<SomeData></SomeData>
</Item>
<Item>
<Heading>Washington></Heading>
<SomeData></SomeData>
</Item>
</List>Input file (Random, not consolidated) <List> <Item> <Heading>Prague</Heading> <SubDiv1>Avenues</SubDiv1> <SubDiv2>Crosswalks</SubDiv2> <SomeData>12</SomeData> </Item> <Item > <Heading>Prague</Heading> <SomeData>1</SomeData> <--- Needs to me consolidated </Item> <Item> <Heading>Prague</Heading> <SubDiv1>Avenues</SubDiv1> <SomeData></SomeData> </Item> <Item> <Heading>Prague</Heading> <SubDiv1>Avenue</SubDiv1> <SubDiv2>Crosswalks</SubDiv2> <SubDiv3>Dangerous</SubDiv3> <SomeData></SomeData> </Item> <Item> <Heading>Bonn</Heading> <SubDiv1>Avenue</SubDiv1> <SubDiv2>Crosswalks</SubDiv2> <SubDiv3>Dangerous</SubDiv3> <SomeData></SomeData> </Item> <Item> <Heading>Prague</Heading> <SubDiv1>Streets</SubDiv1> <SomeData></SomeData> </Item> <Item> <Heading>Washington></Heading> <SomeData></SomeData> </Item> <Item > <Heading>Prague</Heading> <SomeData>2</SomeData><--- Needs to me consolidated </Item> </List>
|

Cart



