Subject: Re: [xsl] Multiple hierarchy grouping (warning: longish) From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 28 May 2010 13:38:31 +0100 |
Dear XSL List,
I would very much appreciate a little guidance over a problem that has already caused me enough grief to cause me to rend my clothes. The problem is an incarnation of the problem of converting flat XML into structured XML, specifically EAD. My problem is with allowing one layer to have multiple parents. So, in this sample XML:
<xsl:for-each select="//Record"> <xsl:if test="Series=$SER">
> <xsl:variable name="BOX" select="Box"/> > <xsl:for-each-group select="//Record" group-by="FolderID"> > <xsl:if test="Box=$BOX">
<r> <Record> <Series>2</Series> <Subseries>1</Subseries> <Box>12</Box> <Folder>17</Folder> <FolderTitle>Symphonic Poem</FolderTitle> <FolderID>223</FolderID> </Record> <Record> <Series>2</Series> <Subseries>1</Subseries> <Box>12</Box> <Folder>18</Folder> <FolderTitle>Requeim Mass</FolderTitle> <FolderID>224</FolderID> </Record> <Record> <Series>2</Series> <Subseries>2</Subseries> <Box>12</Box> <Folder>19</Folder> <FolderTitle>Symphony no. 4</FolderTitle> <FolderID>225</FolderID> </Record> <Record> <Series>3</Series> <Box>12</Box> <Folder>20</Folder> <FolderTitle>Symphony no. 5</FolderTitle> <FolderID>226</FolderID> </Record> <Record> <Series>3</Series> <Box>13</Box> <Folder>1</Folder> <FolderTitle>Chamber music</FolderTitle> <FolderID>227</FolderID> <Item>String Quartet</Item> </Record> <Record> <Series>3</Series> <Box>13</Box> <Folder>1</Folder> <FolderTitle>Chamber music</FolderTitle> <FolderID>227</FolderID> <Item>String Quartet no. 2</Item> </Record> <Record> <Series>3</Series> <Box>13</Box> <Folder>1</Folder> <FolderTitle>Chamber music</FolderTitle> <FolderID>227</FolderID> <Item>Piano Trio Quartet</Item> </Record>
<xsl:template match="r"> <r> <xsl:for-each-group select="Record" group-by="string(Series)"> <Series id="{current-grouping-key()}"> <xsl:for-each-group select="current-group()" group-by="string(Subseries)"> <Subseries id="{current-grouping-key()}"> <xsl:for-each-group select="current-group()" group-by="string(Box)"> <Box id="{current-grouping-key()}"> <xsl:copy-of select="* except (Series,Subseries,Box)"/> </Box> </xsl:for-each-group> </Subseries> </xsl:for-each-group> </Series> </xsl:for-each-group> </r> </xsl:template>
bash-3.2$ saxon9 records.xml records.xsl <r> <Series id="2"> <Subseries id="1"> <Box id="12"> <Folder>17</Folder> <FolderTitle>Symphonic Poem</FolderTitle> <FolderID>223</FolderID> </Box> </Subseries> <Subseries id="2"> <Box id="12"> <Folder>19</Folder> <FolderTitle>Symphony no. 4</FolderTitle> <FolderID>225</FolderID> </Box> </Subseries> </Series> <Series id="3"> <Subseries id=""> <Box id="12"> <Folder>20</Folder> <FolderTitle>Symphony no. 5</FolderTitle> <FolderID>226</FolderID> </Box> <Box id="13"> <Folder>1</Folder> <FolderTitle>Chamber music</FolderTitle> <FolderID>227</FolderID> <Item>String Quartet</Item> </Box> </Subseries> </Series> </r>
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Multiple hierarchy grouping (, Eric | Thread | Re: [xsl] Multiple hierarchy groupi, Eric |
[xsl] Multiple hierarchy grouping (, Eric | Date | Re: [xsl] xsl variable/param questi, Arian |
Month |