create on output multiple xml files
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Tue Feb 12, 2013 10:14 pm
create on output multiple xml files
Hi, I'm very new to transformation scenarios. I'm practicing with a test xml file (see below). What I would like is to create multiple .xml files where each <cd> and its children and information is in a new cd_{position #}.xml file. I've tried using xsl:result-document (see below). In the results, all I get is the following:
<?xml version="1.0" encoding="UTF-8"?> and no files are written to my folder where my xml and xsl files are located. I've also tried using the extension for xslt 1.0 and the result is again nothing written in my folder but the ext:document shows up in my results. I'd prefer to figure this out with xslt 2.0 and xsl:result-document. Any help would be much appreciated.
Thanks,
Jen
xml file:
xslt file:
<?xml version="1.0" encoding="UTF-8"?> and no files are written to my folder where my xml and xsl files are located. I've also tried using the extension for xslt 1.0 and the result is again nothing written in my folder but the ext:document shows up in my results. I'd prefer to figure this out with xslt 2.0 and xsl:result-document. Any help would be much appreciated.
Thanks,
Jen
xml file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" name="xml"/>
<xsl:template match="/">
<xsl:for-each select="cd">
<xsl:result-document method="xml" href="cd_{position()}.xml" encoding="UTF-8" indent="yes">
<catalog>
<xsl:copy-of select="."/>
</catalog>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: create on output multiple xml files
Hi,
Use: This is necessary because <xsl:template match="/"> actually matches the XML document root(#document) not the root element (catalog).
Alternatively, you can change the template to match the root element:
Regards,
Adrian
Use:
Code: Select all
<xsl:for-each select="catalog/cd">
Alternatively, you can change the template to match the root element:
Code: Select all
<xsl:template match="/*">
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
-
- Posts: 2
- Joined: Tue Feb 12, 2013 10:14 pm
Re: create on output multiple xml files
Hi Adrian,
I began with <xsl:for-each select="catalog/cd">. I changed it back. I receive the message that the transformation was successful and took 0.0s to complete and nothing pops up in the result window. Also, no separate xml files are written to my folder where I want them. So I'm still unsure as to what's going on.
I began with <xsl:for-each select="catalog/cd">. I changed it back. I receive the message that the transformation was successful and took 0.0s to complete and nothing pops up in the result window. Also, no separate xml files are written to my folder where I want them. So I'm still unsure as to what's going on.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: create on output multiple xml files
Hi,
Have you tested this change on the XML sample you provided above? That what I tested and it worked for me.
Or do you have a larger XML file and you're testing it against that?
You should consider using the XSLT debugger from Oxygen (Document > Transformation > Debug Scenario) to investigate what's going on.
Regards,
Adrian
Have you tested this change on the XML sample you provided above? That what I tested and it worked for me.
Or do you have a larger XML file and you're testing it against that?
You should consider using the XSLT debugger from Oxygen (Document > Transformation > Debug Scenario) to investigate what's going on.
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
-
- Posts: 2
- Joined: Mon Jun 22, 2015 11:58 pm
Re: create on output multiple xml files
Just in case anyone else has had the same problem as JMarie here:

I solved it when I checked the actual transformer being used in the "Configure Transformation Scenario" dialog box. Even though I had chosen Saxon PE 9.5 in the general preferences, is was not selected in the Transformation Scenario. After selecting Saxon PE 9.5 in that dialog, my transformation worked perfectly. Very puzzling, but happily on to another puzzle now.In the results, all I get is the following:
<?xml version="1.0" encoding="UTF-8"?> and no files are written to my folder where my xml and xsl files are located.
. . .
I receive the message that the transformation was successful and took 0.0s to complete and nothing pops up in the result window.

-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: create on output multiple xml files
Hello kalinma,
But in JMarie's case, it's unlikely that was the problem, because xsl:result-document always fails with an error if using the wrong (XSLT 1.0) transformer.
Note that there is no general preference that sets the default transformer, there's only a general preference for XSLT validation where you can pick the default XSLT engine to be used when validating a specific version of XSLT. The transformer must be selected in the transformation scenario configuration.
Regards,
Adrian
What transformer did you previously use? If you're using the wrong transformer for your stylesheet version, when you run the transformation, Oxygen will prompt you and recommend to switch to Saxon-HE/PE/EE (for XSLT 2.0 or 3.0).kalinma wrote:I solved it when I checked the actual transformer being used in the "Configure Transformation Scenario" dialog box. Even though I had chosen Saxon PE 9.5 in the general preferences, is was not selected in the Transformation Scenario. After selecting Saxon PE 9.5 in that dialog, my transformation worked perfectly. Very puzzling, but happily on to another puzzle now.
But in JMarie's case, it's unlikely that was the problem, because xsl:result-document always fails with an error if using the wrong (XSLT 1.0) transformer.
Note that there is no general preference that sets the default transformer, there's only a general preference for XSLT validation where you can pick the default XSLT engine to be used when validating a specific version of XSLT. The transformer must be selected in the transformation scenario configuration.
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
-
- Posts: 2
- Joined: Mon Jun 22, 2015 11:58 pm
Re: create on output multiple xml files
Hi Adrian,
If you go to Options->Preferences and select XSLT in the list on the left side, you will see options for "XML / XSLT-FO-XQuery / XSLT" and underneath that "JAXP XSLT Transformer". There you can choose a validation engine for each of XSLT 1.0, 2.0, 3.0. This dialog is not the same as the one in "Configure Transformation Scenario." Perhaps this difference is the result of my using oXygen Author (v. 15.2) as my company will not spring for oXygen Developer.
Thanks.
If you go to Options->Preferences and select XSLT in the list on the left side, you will see options for "XML / XSLT-FO-XQuery / XSLT" and underneath that "JAXP XSLT Transformer". There you can choose a validation engine for each of XSLT 1.0, 2.0, 3.0. This dialog is not the same as the one in "Configure Transformation Scenario." Perhaps this difference is the result of my using oXygen Author (v. 15.2) as my company will not spring for oXygen Developer.
Thanks.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: create on output multiple xml files
Hi,
The preferences section you mentioned (Options > Preferences, XML > XSLT-FO-XQuery > XSLT) allows you to pick the XSLT validation engine, but that doesn't affect the transformations in any way. There is no difference regarding these options between Author, Developer, Editor, however, in Author they are actually meaningless, because there's no specialized editor for XSL files, so no support for XSL editing and validation, just support for XSLT transformations (in the "Configure Transformation Scenario(s)" dialog and corresponding view).
Regards,
Adrian
The preferences section you mentioned (Options > Preferences, XML > XSLT-FO-XQuery > XSLT) allows you to pick the XSLT validation engine, but that doesn't affect the transformations in any way. There is no difference regarding these options between Author, Developer, Editor, however, in Author they are actually meaningless, because there's no specialized editor for XSL files, so no support for XSL editing and validation, just support for XSLT transformations (in the "Configure Transformation Scenario(s)" dialog and corresponding view).
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
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