Breaking an XML file into smaller XML files...
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Wed Jul 28, 2010 5:10 pm
Breaking an XML file into smaller XML files...
Hello all!
I have an XML file I have imported from MS Excel. I now need to break the document up into smaller XML documents, each uniquely named using an element value. My guess is I will have to dust off the XSLT textbooks, but I was hoping there was a quicker way to do this in Oxygen than me having to write the transformation. Suggestions for other ways to go about this problem are welcome!
The parent XML file...
Needs to be broken up into 3 separate XML files...
This file should be named 1977.xml
And this file should be named 1978.xml
Cheers, Paul
I have an XML file I have imported from MS Excel. I now need to break the document up into smaller XML documents, each uniquely named using an element value. My guess is I will have to dust off the XSLT textbooks, but I was hoping there was a quicker way to do this in Oxygen than me having to write the transformation. Suggestions for other ways to go about this problem are welcome!
The parent XML file...
Code: Select all
<row>
<dc:title>paul</dc:title>
<dc:creator>mom</dc:creator>
<dc:identifier>1977</dc:identifier>
</row>
<row>
<dc:title>brad</dc:title>
<dc:creator>dad</dc:creator>
<dc:identifier>1978</dc:identifier>
</row>
<row>
<dc:title>melissa</dc:title>
<dc:creator>mom and dad</dc:creator>
<dc:identifier>1979</dc:identifier>
</row>
This file should be named 1977.xml
Code: Select all
<row>
<dc:title>paul</dc:title>
<dc:creator>mom</dc:creator>
<dc:identifier>1977</dc:identifier>
</row>
Code: Select all
<row>
<dc:title>brad</dc:title>
<dc:creator>dad</dc:creator>
<dc:identifier>1978</dc:identifier>
</row>
Cheers, Paul
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Breaking an XML file into smaller XML files...
Hello,
Here's no quicker way than a stylesheet.
Try with this one:
You may need to make some small adjustments to the root element name and the namespace associated with the dc prefix.
Regards,
Adrian
Here's no quicker way than a stylesheet.
Try with this one:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:dc="myns">
<xsl:template match="/">
<xsl:for-each-group select="//row" group-by="dc:identifier/text()">
<xsl:result-document href="{concat(current-grouping-key(), '.xml')}" method="xml">
<xsl:element name="root">
<xsl:copy-of select="current-group()"/>
</xsl:element>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service