[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|