Re: [xsl] splitting one xml into many xml documents using xsl

Subject: Re: [xsl] splitting one xml into many xml documents using xsl
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Fri, 09 Mar 2001 10:02:03 -0800
It depends on the processor you are using, for example with xalan you could
do something like (notice the 'redirect' extension) what I have included
below. It does not fit with your situation but you could probably derive
what you need from it. Also I used output as text as opposed to XML which
might be better for your needs.  You can also do the same thing in Saxon
(and probably others) but I have not used it yet.

<?xml version="1.0" encoding="UTF-8"?>

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

<xsl:template match="/">
<xsl:value-of select="count(//page)"/>
   <redirect:write file="pagelist.xml">&lt;?xml version="1.0"
encoding="ISO-8859-1"?&gt;
      &lt;translation&gt;
         <xsl:apply-templates select="//page"/>
      &lt;/translation&gt;
   </redirect:write>
</xsl:template>

<xsl:template match="page">
   <xsl:variable name="path" select="../@folder"/>
   <xsl:variable name="name" select="output/@filename"/>
   <xsl:variable name="outputfile"
select="concat($path,'/',$name,'_x.xml')"/>

      &lt;file&gt;
        &lt;xml&gt;<xsl:value-of select="$outputfile"/>&lt;/xml&gt;
        &lt;xsl&gt;<xsl:value-of select="xstylesheet/@fileref"/>&lt;/xsl&gt;
        &lt;out&gt;<xsl:value-of
select="concat($path,'/',$name,'.html')"/>&lt;/out&gt;
      &lt;/file&gt;
</xsl:template>

</xsl:stylesheet>




----- Original Message -----
From: "murali meraga" <meraga_m@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, March 09, 2001 9:47 AM
Subject: [xsl] splitting one xml into many xml documents using xsl


> Hi,
>
>   Here is details about my problem. I have the
> folloing adddress.xml document
>
> <?xml version="1.0" encoding="UTF-8"?>
>   <address_object>
>        <address1>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
>        </address1>
>        <address2>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
>        </address2>
>        <address3>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
>        </address3>
>  </address_object>
>
> and I want to split the above xml into the follwing
> xml documents. How can I do that using xsl?
>
> ------------address1.xml -------------
> <?xml version="1.0" encoding="UTF-8"?>
> <address1>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
> </address1>
>
> ----------addrees2.xml --------
> <?xml version="1.0" encoding="UTF-8"?>
> <address2>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
> </address2>
> ------------- address3.xml --------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <address3>
>            <name>x</name>
>            <street>1925 x street</street>
>            <city>x city</city>
>            <zip>0000</zip>
> </address3>
>
> Thanks in advance.
>

>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread