[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
On 28/05/2010 05:21, Eric wrote:
I think your main problem is that you are using //
here you are recursively searching the entire document looking for Record elements, and then only using them if Series=$SER
so i suspect all your Record elements are siblings 9so you don't want //) and you can filter on Series, so
<xsl:for-each select="Record[Series=$SER]"
except that if you had already done a for-each-group, grouping on Series then there is no need to search the whole document, filtering of series, you just want the records in this group, ie
select="current-group()"
similiarly here:
You are seraching the entire document at all levels but you just want the Records that have already been grouped by Box so thi sis again
select="current-group()
I'm not sure I fully understood the output format you gave, and teh input wansn't a full document so I wrapped it in <r>, but possibly something like the following
</r>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
</xsl:stylesheet>
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________
Re: [xsl] Multiple hierarchy grouping (warning: longish)
Subject: Re: [xsl] Multiple hierarchy grouping (warning: longish) From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 28 May 2010 13:38:31 +0100 |
On 28/05/2010 05:21, Eric wrote:
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:
I think your main problem is that you are using //
<xsl:for-each select="//Record"> <xsl:if test="Series=$SER">
here you are recursively searching the entire document looking for Record elements, and then only using them if Series=$SER
so i suspect all your Record elements are siblings 9so you don't want //) and you can filter on Series, so
<xsl:for-each select="Record[Series=$SER]"
except that if you had already done a for-each-group, grouping on Series then there is no need to search the whole document, filtering of series, you just want the records in this group, ie
select="current-group()"
similiarly here:
> <xsl:variable name="BOX" select="Box"/> > <xsl:for-each-group select="//Record" group-by="FolderID"> > <xsl:if test="Box=$BOX">
You are seraching the entire document at all levels but you just want the Records that have already been grouped by Box so thi sis again
select="current-group()
I'm not sure I fully understood the output format you gave, and teh input wansn't a full document so I wrapped it in <r>, but possibly something like the following
<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>
</r>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<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>
</xsl:stylesheet>
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.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________
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 |