Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2006, 02:37 PM
Registered User
 
Join Date: Mar 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple doc'ts w/ specific record elements counts

Hi,
Has anyone ever tried splitting a document into multiple documents by specifying a maximum number of elements that they would want in each split document? I have a partial solution as each output only gets the last element. Here is my transformation:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:WVS="http://geodepot.statcan.ca/wvs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:WVS2="http://geodepot.statcan.ca/wvs" xmlns:wfs="http://www.opengis.net/wfs">
    <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="no"/>

    <xsl:variable name="concept" select="('csd')"/>
    <xsl:template match="/">
        <xsl:for-each select="$concept">

            <xsl:variable name="index" select="position()"/>
            <xsl:variable name="out_file" select="$concept[$index]"/>
            <xsl:variable name="in_file" select="concat($concept[$index], '.xml')"/>
            <xsl:for-each select="document($in_file)/wfs:FeatureCollection/gml:featureMember">
                <xsl:variable name="suffix" select="position() idiv 10"/>
                <xsl:variable name="in_transaction">
                    <xsl:copy-of select="child::*"/>
                </xsl:variable>
                <xsl:if test="position() mod 10 = 0">
                    <xsl:call-template name="write_output">
                        <xsl:with-param name="out_file" select="$out_file"/>
                        <xsl:with-param name="suffix" select="$suffix"/>
                        <xsl:with-param name="transaction" select="$in_transaction"/>
                    </xsl:call-template>
                </xsl:if>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="write_output">
        <xsl:param name="out_file"/>
        <xsl:param name="suffix"/>
        <xsl:param name="transaction"/>
        <xsl:result-document indent="yes" encoding="ISO-8859-1" href="{$out_file}_{$suffix}_transaction.xml">
            <wfs:Transaction>
                <xsl:attribute name="version">1.0.0</xsl:attribute>
                <xsl:attribute name="service">WFS</xsl:attribute>
                <wfs:Insert>
                    <xsl:copy-of select="$transaction"/>
                </wfs:Insert>
            </wfs:Transaction>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>
Any input is greatly appreciated!
Cheers,
Francine.
 
Old March 21st, 2006, 03:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is essentially the same problem as splitting data across the rows of a table for which the canonical solution is at

http://www.dpawson.co.uk/xsl/sect2/N7450.html#d9550e13

Your code doesn't work, of course, because you only output anything if position() mod 10 = 0, which is only true once every 10 items. What you need to do is

if position() mod 10 = 1
  <group>
  process the items from position() to position()+10 inclusive
  </group>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 29th, 2006, 11:25 AM
Registered User
 
Join Date: Mar 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the information! I was able to get it to work for me!






Similar Threads
Thread Thread Starter Forum Replies Last Post
first n elements with highest counts in a group manish_jaiswal XSLT 6 February 8th, 2008 09:16 PM
choose specific record ar555 Dreamweaver (all versions) 12 January 12th, 2007 01:04 PM
Access specific Element and its Child elements! suersh79 XML 3 November 22nd, 2006 12:58 AM
Link to a specific record rexecampbell Classic ASP Basics 2 April 7th, 2004 01:40 PM
efficiency qn xml vs sql server - to record counts ak Classic ASP Databases 3 March 3rd, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.