Subject: RE: Grouping Question
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 11 Jun 2007 20:17:47 +0100
|
Just change
<xsl:apply-templates select="."/>
to
<xsl:apply-templates select="current-group()"/>
Actually, since you're not making changes, I think you could do
<xsl:copy-of select="current-group()"/>
One other point: the href attribute of xsl:result-document is supposed to be
a URI, not a Windows filename.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Danny Leblanc [mailto:leblancd@xxxxxxxxxxxxxxxxxxx]
> Sent: 11 June 2007 19:49
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Grouping Question
>
> Hello everyone,
>
> Let say I have an XML file that looks like this
>
> <root>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> <L1>Data</L1>
> </root>
>
> What I want to do is split this into multiple files each
> time a new L1 is found. The following code is what I use.
> (The code for this is more or less generic except for the XPATH).
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" version="1.0" encoding="utf-8"
> indent="yes"/>
> <xsl:template match="/">
> <xsl:for-each select="root/L1">
> <xsl:result-document
> href="C:\\out\\{format-number(position(),'000000000')}.xml">
> <reportrun>
> <batch>
> <xsl:apply-templates select="."/>
> </batch>
> </reportrun>
> </xsl:result-document>
> </xsl:for-each>
> </xsl:template>
> <xsl:template match="@*|node()">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
> This works A1, just the way I want it to. Now what I would
> like to do is add an option that would allow the user to do
> the same split but they could choose how many "L1" would go
> into the output file. For example, right now the above case
> creates 8 files, one per L1. I would like to output 4 files
> that would each contain 2 L1 nodes.
>
> I tried something like this
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" version="1.0" encoding="utf-8"
> indent="yes"/>
> <xsl:template match="/">
> <xsl:for-each-group select="root/L1"
> group-by="L1[position() mod 5 = 0]">
> <xsl:result-document
> href="C:\\out\\{format-number(position(),'000000000')}.xml">
> <reportrun>
> <batch>
> <xsl:apply-templates select="."/>
> </batch>
> </reportrun>
> </xsl:result-document>
> </xsl:for-each-group>
> </xsl:template>
> <xsl:template match="@*|node()">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
> Which did not work. Any insights as to what I would have to
> change to get this going would be appreciated.
>
> Thank you in advance.
|