aspose file tools*
The moose likes XML and Related Technologies and the fly likes Split xml using xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Split xml using xsl" Watch "Split xml using xsl" New topic
Author

Split xml using xsl

S Mithal
Greenhorn

Joined: Mar 17, 2005
Posts: 19
Hi,

I am trying to split an xml using xslt. For this I am using <redirect:write> which is Xalan specific. Is there an alternative tag I can use and get the same functionality?

This is an example xml file:

<?xml version="1.0" encoding="UTF-8"?>
<MyFType>
<MyRType>
<MCode>
<ID>1</ID>
<Title>ABC</Title>
<ShortSummary>EFG</ShortSummary>
</MCode>
</MyRType>
<MyRType>
<MCode>
<ID>2</ID>
<Title>WER</Title>
<ShortSummary>EFG</ShortSummary>
</MCode>
</MyRType>
</MyFType>

This is the xslt which will split the above into 1.xml and 2.xml

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect"
version="1.0"
>
<xsl utput method="xml"/>

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="MyFType">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="MyRType">
<xsl:variable name="filename" select="concat(MCode/ID,'.xml')" />
<redirect:write select="$filename">
<MyRType>
<xsl:apply-templates />
</MyRType>
</redirect:write>
</xsl:template>

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

</xsl:stylesheet>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

No. XSLT 1.0 does not include that functionality, but several of its implementations (Xalan, Saxon that I know of) have provided implementation-specific ways to write to multiple destinations from a single XSLT.

XSLT 2.0 does provide the ability to write to multiple destinations, I believe, but no JRE comes with XSLT 2.0 build in. You would have to get an XSLT 2.0 implementation (they do exist) and make sure that you were calling it from your Java code.
S Mithal
Greenhorn

Joined: Mar 17, 2005
Posts: 19
Thanks for your post. I read the same while trying to explore this issue, but wanted to confirm if there was an alternative to <redirect:write>.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Split xml using xsl
 
Similar Threads
Simple XSL problem: parent attributes
Multiple file output with JDK 6 XSLT implementation
XSLT Wrong Result Set?
want to generate wml from xsl file
want to generate wml file from a xsl file