splitting an xml file to multiple xml files

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

splitting an xml file to multiple xml files

ram.shankar
Hello
I want to split one xml file to multiple xml files.

The following is my requirement.

I have an xml file .Let us call it : A.xml
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<import>
      <header>
            <system>Matrix</system>
            <fileid/>
      </header>
      <data>
            <entity>TESTENTITY1</entity>
            <docclause>DOC1</docclause>

      </data>
      <data>
            <entity>TESTENTITY2</entity>
            <docclause>DOC2</docclause>

      </data>

</import>
---------------------------------------------

I have to split it two files B.xml and C.xml .. but the structure remains
the same

B.xml.....
-------
<?xml version="1.0" encoding="UTF-8"?>
<import>
      <header>
            <system>Matrix</system>
            <fileid/>
      </header>
      <data>
            <entity>TESTENTITY1</entity>
            <docclause>DOC1</docclause>

      </data>

</import>
------------------------------------------
C.xml ....
<?xml version="1.0" encoding="UTF-8"?>
<import>
      <header>
            <system>Matrix</system>
            <fileid/>
      </header>
      <data>
            <entity>TESTENTITY2</entity>
            <docclause>DOC2</docclause>

      </data>
</import>

--------------------------------------------------

I believe saxon can help me achieve that. Since I am new to this field I
would appreciate if someone could show me the way how to do it or guide me
to an appropriate link where i can get  an example.

Thanks
Ram
*************************************************************************
This message and any attachments (the "message") are confidential and intended solely for the addressee(s).
Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration.  
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or
falsified.
                              ************
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses
destinataires. Toute utilisation ou diffusion non autorisee est interdite. Tout message electronique est susceptible d'alteration.
La SOCIETE GENERALE et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie.
*************************************************************************


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: splitting an xml file to multiple xml files

neil atkinson
This may not be the best way to do it, but its a starting point

The template will iterate over your data nodes building a result document
for each, regardless of how many there are, and since you only want to copy
the header information (of which there is only one) to each, just call a
template to copy it.

<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/02/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

 <xsl:template match="/">
  <xsl:for-each select="import/data">
   <xsl:variable name="filename" select="entity"/>
     <xsl:result-document href="{$filename}.xml">
          <xsl:element name="import">
              <xsl:apply-templates select="//header"/>
               <xsl:copy-of select="."/>
          </xsl:element>
     </xsl:result-document>
  </xsl:for-each>
 </xsl:template>

 <xsl:template match="header">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

Rather than call them B.xml and C.xml ive used the entity name as the file
name.
There are other ways to do this if this doesnt fit the purpose.
Id also be interested in any other methods of solving the problem.

Im using the saxon8 jar file and cmd line

java -jar saxon8.jar -o o.html split.xml split.xsl

Neil



----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, October 26, 2005 9:26 AM
Subject: [saxon] splitting an xml file to multiple xml files


> Hello
> I want to split one xml file to multiple xml files.
>
> The following is my requirement.
>
> I have an xml file .Let us call it : A.xml
> ------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
>
> </import>
> ---------------------------------------------
>
> I have to split it two files B.xml and C.xml .. but the structure remains
> the same
>
> B.xml.....
> -------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>
> </import>
> ------------------------------------------
> C.xml ....
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
> </import>
>
> --------------------------------------------------
>
> I believe saxon can help me achieve that. Since I am new to this field I
> would appreciate if someone could show me the way how to do it or guide me
> to an appropriate link where i can get  an example.
>
> Thanks
> Ram
> *************************************************************************
> This message and any attachments (the "message") are confidential and
intended solely for the addressee(s).
> Any unauthorised use or dissemination is prohibited. E-mails are
susceptible to alteration.
> Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or
> falsified.
>                               ************
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses
> destinataires. Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.

> *************************************************************************
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: splitting an xml file to multiple xml files

ram.shankar
In reply to this post by ram.shankar
Thanks Neil,
This solution you gave is indeed good.
But I need to split the file based on a max size. Only if the size is
greater than a specified size, I have to split the files. So it may so
happen that one of the resultant files (after splitting)  may have 2 data
nodes and next will have only one.

I think my question in the first place was not complete.

Thanks for the help.



-rgds
Ram



                                                                                                                                                 
                      [hidden email]                                                                                                    
                      Sent by:                           To:       [hidden email]                                              
                      [hidden email]        cc:                                                                                    
                      ceforge.net                        Subject:  Re: [saxon] splitting an xml file to multiple xml files                      
                                                                                                                                                 
                                                                                                                                                 
                      10/26/2005 02:44 PM                                                                                                        
                      Please respond to                                                                                                          
                      saxon-help                                                                                                                
                                                                                                                                                 
                                                                                                                                                 




This may not be the best way to do it, but its a starting point

The template will iterate over your data nodes building a result document
for each, regardless of how many there are, and since you only want to copy
the header information (of which there is only one) to each, just call a
template to copy it.

<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/02/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

 <xsl:template match="/">
  <xsl:for-each select="import/data">
   <xsl:variable name="filename" select="entity"/>
     <xsl:result-document href="{$filename}.xml">
          <xsl:element name="import">
              <xsl:apply-templates select="//header"/>
               <xsl:copy-of select="."/>
          </xsl:element>
     </xsl:result-document>
  </xsl:for-each>
 </xsl:template>

 <xsl:template match="header">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

Rather than call them B.xml and C.xml ive used the entity name as the file
name.
There are other ways to do this if this doesnt fit the purpose.
Id also be interested in any other methods of solving the problem.

Im using the saxon8 jar file and cmd line

java -jar saxon8.jar -o o.html split.xml split.xsl

Neil



----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, October 26, 2005 9:26 AM
Subject: [saxon] splitting an xml file to multiple xml files


> Hello
> I want to split one xml file to multiple xml files.
>
> The following is my requirement.
>
> I have an xml file .Let us call it : A.xml
> ------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
>
> </import>
> ---------------------------------------------
>
> I have to split it two files B.xml and C.xml .. but the structure remains
> the same
>
> B.xml.....
> -------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>
> </import>
> ------------------------------------------
> C.xml ....
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
> </import>
>
> --------------------------------------------------
>
> I believe saxon can help me achieve that. Since I am new to this field I
> would appreciate if someone could show me the way how to do it or guide
me
> to an appropriate link where i can get  an example.
>
> Thanks
> Ram
> *************************************************************************
> This message and any attachments (the "message") are confidential and
intended solely for the addressee(s).
> Any unauthorised use or dissemination is prohibited. E-mails are
susceptible to alteration.
> Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or
> falsified.
>                               ************
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses
> destinataires. Toute utilisation ou diffusion non autorisee est
interdite.
Tout message electronique est susceptible d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.

> *************************************************************************
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
 https://lists.sourceforge.net/lists/listinfo/saxon-help

*************************************************************************
This message and any attachments (the "message") are confidential and intended solely for the addressee(s).
Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration.  
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or
falsified.
                              ************
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses
destinataires. Toute utilisation ou diffusion non autorisee est interdite. Tout message electronique est susceptible d'alteration.
La SOCIETE GENERALE et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie.
*************************************************************************


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: splitting an xml file to multiple xml files

Michael Kay
In reply to this post by ram.shankar
You've been given the basic mechanism for writing multiple output files. The
rest of your task is to identify which parts of the input go into which
file. You haven't given enough information about the algorithm you want to
use to decide this.

In general, the usual approach is a "sibling recursion" that processes the
elements on the sibling axis using a recursive template, passing a parameter
on the recursive call that accumulates the number of lines/records read so
far, and starts a new page/document when this reaches some threshold.

The following example shows the general idea: it outputs a page break before
any SPEECH that would cause the accumulated number of LINEs to exceed 30:

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
<xsl:strip-space elements="*"/>

<xsl:output method="xml" indent="yes"/>
   
<xsl:template match="SCENE">
  <xsl:copy>
    <xsl:apply-templates select="*[1]">
      <xsl:with-param name="lines" select="0"/>
    </xsl:apply-templates>
  </xsl:copy>  
</xsl:template>

<xsl:template match="SCENE/*">
  <xsl:param name="lines"/>
  <!--<xsl:comment>Lines: <xsl:value-of select="$lines"/></xsl:comment>-->
  <xsl:variable name="more-lines" select="count(LINE)"/>
  <xsl:variable name="overflow" select="$lines + $more-lines > 30"/>
  <xsl:if test="$overflow">
    <PAGE-BREAK/>
  </xsl:if>
  <xsl:copy-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1]">
    <xsl:with-param name="lines">
      <xsl:choose>
        <xsl:when test="$overflow"><xsl:value-of
select="$more-lines"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="$lines +
$more-lines"/></xsl:otherwise>
      </xsl:choose>
    </xsl:with-param>  
  </xsl:apply-templates>
</xsl:template>

</xsl:stylesheet>

(However this is really a topic for the xsl-list at mulberrytech.com, as
it's not really a Saxon question)


Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 26 October 2005 09:27
> To: [hidden email]
> Subject: [saxon] splitting an xml file to multiple xml files
>
> Hello
> I want to split one xml file to multiple xml files.
>
> The following is my requirement.
>
> I have an xml file .Let us call it : A.xml
> ------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
>
> </import>
> ---------------------------------------------
>
> I have to split it two files B.xml and C.xml .. but the
> structure remains
> the same
>
> B.xml.....
> -------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>
> </import>
> ------------------------------------------
> C.xml ....
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
> </import>
>
> --------------------------------------------------
>
> I believe saxon can help me achieve that. Since I am new to
> this field I
> would appreciate if someone could show me the way how to do
> it or guide me
> to an appropriate link where i can get  an example.
>
> Thanks
> Ram
> **************************************************************
> ***********
> This message and any attachments (the "message") are
> confidential and intended solely for the addressee(s).
> Any unauthorised use or dissemination is prohibited. E-mails
> are susceptible to alteration.  
> Neither SOCIETE GENERALE nor any of its subsidiaries or
> affiliates shall be liable for the message if altered, changed or
> falsified.
>                               ************
> Ce message et toutes les pieces jointes (ci-apres le
> "message") sont confidentiels et etablis a l'intention
> exclusive de ses
> destinataires. Toute utilisation ou diffusion non autorisee
> est interdite. Tout message electronique est susceptible
> d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute
> responsabilite au titre de ce message s'il a ete altere,
> deforme ou falsifie.
> **************************************************************
> ***********
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: splitting an xml file to multiple xml files

ram.shankar
In reply to this post by ram.shankar
Hello Mike,
Thanks for the solution. I could figure out the solution. But I still have
a problem
After I encounter <PAGE-BREAK/> how do I redirect the rest of the content
to a new file.

I tried <xsl:result-document href="file.xml" format="testformat"> option
but I get a java error when I am doing the transformation that goes like
this:
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: "name" attribute is not allowed
on the xsl:output element!

Is there any help available for this ?

Aplogies for mailing in this list and not in mulberrytech.com,  as I would
lose continuity.


Thanks and Regards
Ram



                                                                                                                                                 
                      [hidden email]                                                                                                          
                      Sent by:                           To:       [hidden email]                                              
                      [hidden email]        cc:                                                                                    
                      ceforge.net                        Subject:  RE: [saxon] splitting an xml file to multiple xml files                      
                                                                                                                                                 
                                                                                                                                                 
                      10/27/2005 02:57 AM                                                                                                        
                      Please respond to                                                                                                          
                      saxon-help                                                                                                                
                                                                                                                                                 
                                                                                                                                                 




You've been given the basic mechanism for writing multiple output files.
The
rest of your task is to identify which parts of the input go into which
file. You haven't given enough information about the algorithm you want to
use to decide this.

In general, the usual approach is a "sibling recursion" that processes the
elements on the sibling axis using a recursive template, passing a
parameter
on the recursive call that accumulates the number of lines/records read so
far, and starts a new page/document when this reaches some threshold.

The following example shows the general idea: it outputs a page break
before
any SPEECH that would cause the accumulated number of LINEs to exceed 30:

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="SCENE">
  <xsl:copy>
    <xsl:apply-templates select="*[1]">
      <xsl:with-param name="lines" select="0"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="SCENE/*">
  <xsl:param name="lines"/>
  <!--<xsl:comment>Lines: <xsl:value-of select="$lines"/></xsl:comment>-->
  <xsl:variable name="more-lines" select="count(LINE)"/>
  <xsl:variable name="overflow" select="$lines + $more-lines > 30"/>
  <xsl:if test="$overflow">
    <PAGE-BREAK/>
  </xsl:if>
  <xsl:copy-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1]">
    <xsl:with-param name="lines">
      <xsl:choose>
        <xsl:when test="$overflow"><xsl:value-of
select="$more-lines"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="$lines +
$more-lines"/></xsl:otherwise>
      </xsl:choose>
    </xsl:with-param>
  </xsl:apply-templates>
</xsl:template>

</xsl:stylesheet>

(However this is really a topic for the xsl-list at mulberrytech.com, as
it's not really a Saxon question)


Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 26 October 2005 09:27
> To: [hidden email]
> Subject: [saxon] splitting an xml file to multiple xml files
>
> Hello
> I want to split one xml file to multiple xml files.
>
> The following is my requirement.
>
> I have an xml file .Let us call it : A.xml
> ------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
>
> </import>
> ---------------------------------------------
>
> I have to split it two files B.xml and C.xml .. but the
> structure remains
> the same
>
> B.xml.....
> -------
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY1</entity>
>             <docclause>DOC1</docclause>
>
>       </data>
>
> </import>
> ------------------------------------------
> C.xml ....
> <?xml version="1.0" encoding="UTF-8"?>
> <import>
>       <header>
>             <system>Matrix</system>
>             <fileid/>
>       </header>
>       <data>
>             <entity>TESTENTITY2</entity>
>             <docclause>DOC2</docclause>
>
>       </data>
> </import>
>
> --------------------------------------------------
>
> I believe saxon can help me achieve that. Since I am new to
> this field I
> would appreciate if someone could show me the way how to do
> it or guide me
> to an appropriate link where i can get  an example.
>
> Thanks
> Ram
> **************************************************************
> ***********
> This message and any attachments (the "message") are
> confidential and intended solely for the addressee(s).
> Any unauthorised use or dissemination is prohibited. E-mails
> are susceptible to alteration.
> Neither SOCIETE GENERALE nor any of its subsidiaries or
> affiliates shall be liable for the message if altered, changed or
> falsified.
>                               ************
> Ce message et toutes les pieces jointes (ci-apres le
> "message") sont confidentiels et etablis a l'intention
> exclusive de ses
> destinataires. Toute utilisation ou diffusion non autorisee
> est interdite. Tout message electronique est susceptible
> d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute
> responsabilite au titre de ce message s'il a ete altere,
> deforme ou falsifie.
> **************************************************************
> ***********
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
 https://lists.sourceforge.net/lists/listinfo/saxon-help



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: splitting an xml file to multiple xml files

Michael Kay
I think the error

"name" attribute is
> not allowed
> on the xsl:output element!

is not coming from Saxon, or at least not from any recent Saxon release.
Please try running with the -t option to verify what you are running.

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 28 October 2005 06:13
> To: [hidden email]
> Subject: RE: [saxon] splitting an xml file to multiple xml files
>
> Hello Mike,
> Thanks for the solution. I could figure out the solution. But
> I still have
> a problem
> After I encounter <PAGE-BREAK/> how do I redirect the rest of
> the content
> to a new file.
>
> I tried <xsl:result-document href="file.xml"
> format="testformat"> option
> but I get a java error when I am doing the transformation
> that goes like
> this:
> javax.xml.transform.TransformerConfigurationException:
> javax.xml.transform.TransformerConfigurationException:
> javax.xml.transform.TransformerException:
> javax.xml.transform.TransformerException: "name" attribute is
> not allowed
> on the xsl:output element!
>
> Is there any help available for this ?
>
> Aplogies for mailing in this list and not in
> mulberrytech.com,  as I would
> lose continuity.
>
>
> Thanks and Regards
> Ram
>
>
>
>                                                              
>                                                              
>                      
>                       [hidden email]                      
>                                                              
>                      
>                       Sent by:                           To:  
>      [hidden email]                        
>                      
>                       [hidden email]        cc:  
>                                                              
>                      
>                       ceforge.net                        
> Subject:  RE: [saxon] splitting an xml file to multiple xml
> files                      
>                                                              
>                                                              
>                      
>                                                              
>                                                              
>                      
>                       10/27/2005 02:57 AM                    
>                                                              
>                      
>                       Please respond to                      
>                                                              
>                      
>                       saxon-help                              
>                                                              
>                      
>                                                              
>                                                              
>                      
>                                                              
>                                                              
>                      
>
>
>
>
> You've been given the basic mechanism for writing multiple
> output files.
> The
> rest of your task is to identify which parts of the input go
> into which
> file. You haven't given enough information about the
> algorithm you want to
> use to decide this.
>
> In general, the usual approach is a "sibling recursion" that
> processes the
> elements on the sibling axis using a recursive template, passing a
> parameter
> on the recursive call that accumulates the number of
> lines/records read so
> far, and starts a new page/document when this reaches some threshold.
>
> The following example shows the general idea: it outputs a page break
> before
> any SPEECH that would cause the accumulated number of LINEs
> to exceed 30:
>
> <xsl:stylesheet version="1.0"
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:strip-space elements="*"/>
>
> <xsl:output method="xml" indent="yes"/>
>
> <xsl:template match="SCENE">
>   <xsl:copy>
>     <xsl:apply-templates select="*[1]">
>       <xsl:with-param name="lines" select="0"/>
>     </xsl:apply-templates>
>   </xsl:copy>
> </xsl:template>
>
> <xsl:template match="SCENE/*">
>   <xsl:param name="lines"/>
>   <!--<xsl:comment>Lines: <xsl:value-of
> select="$lines"/></xsl:comment>-->
>   <xsl:variable name="more-lines" select="count(LINE)"/>
>   <xsl:variable name="overflow" select="$lines + $more-lines > 30"/>
>   <xsl:if test="$overflow">
>     <PAGE-BREAK/>
>   </xsl:if>
>   <xsl:copy-of select="."/>
>   <xsl:apply-templates select="following-sibling::*[1]">
>     <xsl:with-param name="lines">
>       <xsl:choose>
>         <xsl:when test="$overflow"><xsl:value-of
> select="$more-lines"/></xsl:when>
>         <xsl:otherwise><xsl:value-of select="$lines +
> $more-lines"/></xsl:otherwise>
>       </xsl:choose>
>     </xsl:with-param>
>   </xsl:apply-templates>
> </xsl:template>
>
> </xsl:stylesheet>
>
> (However this is really a topic for the xsl-list at
> mulberrytech.com, as
> it's not really a Saxon question)
>
>
> Michael Kay
> http://www.saxonica.com/
>
>
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf Of
> > [hidden email]
> > Sent: 26 October 2005 09:27
> > To: [hidden email]
> > Subject: [saxon] splitting an xml file to multiple xml files
> >
> > Hello
> > I want to split one xml file to multiple xml files.
> >
> > The following is my requirement.
> >
> > I have an xml file .Let us call it : A.xml
> > ------------------------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <import>
> >       <header>
> >             <system>Matrix</system>
> >             <fileid/>
> >       </header>
> >       <data>
> >             <entity>TESTENTITY1</entity>
> >             <docclause>DOC1</docclause>
> >
> >       </data>
> >       <data>
> >             <entity>TESTENTITY2</entity>
> >             <docclause>DOC2</docclause>
> >
> >       </data>
> >
> > </import>
> > ---------------------------------------------
> >
> > I have to split it two files B.xml and C.xml .. but the
> > structure remains
> > the same
> >
> > B.xml.....
> > -------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <import>
> >       <header>
> >             <system>Matrix</system>
> >             <fileid/>
> >       </header>
> >       <data>
> >             <entity>TESTENTITY1</entity>
> >             <docclause>DOC1</docclause>
> >
> >       </data>
> >
> > </import>
> > ------------------------------------------
> > C.xml ....
> > <?xml version="1.0" encoding="UTF-8"?>
> > <import>
> >       <header>
> >             <system>Matrix</system>
> >             <fileid/>
> >       </header>
> >       <data>
> >             <entity>TESTENTITY2</entity>
> >             <docclause>DOC2</docclause>
> >
> >       </data>
> > </import>
> >
> > --------------------------------------------------
> >
> > I believe saxon can help me achieve that. Since I am new to
> > this field I
> > would appreciate if someone could show me the way how to do
> > it or guide me
> > to an appropriate link where i can get  an example.
> >
> > Thanks
> > Ram
> > **************************************************************
> > ***********
> > This message and any attachments (the "message") are
> > confidential and intended solely for the addressee(s).
> > Any unauthorised use or dissemination is prohibited. E-mails
> > are susceptible to alteration.
> > Neither SOCIETE GENERALE nor any of its subsidiaries or
> > affiliates shall be liable for the message if altered, changed or
> > falsified.
> >                               ************
> > Ce message et toutes les pieces jointes (ci-apres le
> > "message") sont confidentiels et etablis a l'intention
> > exclusive de ses
> > destinataires. Toute utilisation ou diffusion non autorisee
> > est interdite. Tout message electronique est susceptible
> > d'alteration.
> > La SOCIETE GENERALE et ses filiales declinent toute
> > responsabilite au titre de ce message s'il a ete altere,
> > deforme ou falsifie.
> > **************************************************************
> > ***********
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by the JBoss Inc.
> > Get Certified Today * Register for a JBoss Training Course
> > Free Certification Exam for All Training Attendees Through
> End of 2005
> > Visit http://www.jboss.com/services/certification for more
> information
> > _______________________________________________
> > saxon-help mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/saxon-help
> >
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
>  https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help