• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Split xml using xsl

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>.
 
reply
    Bookmark Topic Watch Topic
  • New Topic