Hello 

XMLTask is perfect for my needs, but I have two additional requirements I 
struggle with. 
I need to:

- iterate over a whole structure and preserve this structure also in the result 
directory root
- modify the resulting file name based on a value from the document.

Also I want to add an attribute = document-url(/) (Saxon8 XSLT2.0 function) to 
the root node of the new document.

Can I do something like the following? Code is missing in some places:

    <target name="3_SplitDocuments" depends="2_RemoveUnneededTags">     
        
        <!-- Cut out <contentitem>s and place in seperate files. Use @name as 
filename addition -->
        <xmltask>
                <fileset dir="${source-root}" includes="**/*.xml"/> <-- ITERATE 
OVER FOLDERS
                
                        <call path="/contentitem" target="CreateFile" 
buffer="contentitem" inheritAll="true">
                                <param name="name" path="@name"/>       <-- 
store /[EMAIL PROTECTED] for result file name modifier
                        </call>
        </xmltask>
        </target>       
        
        <target name="CreateFile">      v--- keep folder structure but add 
something to filename        
                <xmltask todir="${result-root}" dest="??oldfilename?? + 
${name}.xml">                   
                        <insert path="/" buffer="contentitem"/>
                        <attr path="/contentitem" attr="id" 
value="document-uri(/)"/> <-- add value to newly inserted root
                </xmltask>
        </target>    

Thanks in advance,

Robert

-----Original Message-----
From: Brian Agnew [mailto:[EMAIL PROTECTED] 
Sent: Freitag, 3. Dezember 2004 17:07
To: Ant Users List
Subject: Re: Split XML file into seperate files with XSLT and ANT


You should be able to do something like the below (from the sourcecode 
download tests/examples). This creates named xml files 
output-n1.out.xml, output-n2.out.xml from the input
<a>
  <b id="1" attr="n1">Number 1</b>
  <b id="2" attr="n2">Number 2</b>
</a>

Any more queries drop me a line direct or there's an xmltask mailing 
list. See the web page for more details.

Brian

Ant invocations follow.....

<target name="test">
    <!-- call subtargets using 78.xml as the driver -->
    <xmltask source="78.xml">
      <call path="/a/b" target="ab" buffer="b_ab" inheritAll="true">
        <param name="1" path="text()"/>
        <param name="2" path="@attr"/>
        <param name="3" value="${os.name}"/>
      </call>
    </xmltask>
  </target>

  <target name="ab">
    <xmltask dest="output-${2}.out.xml">
      <insert path="/">
        <![CDATA[
          <root/>
        ]]>
      </insert>

      <insert path="/root">[1 = ${1}]</insert>
      <insert path="/root">[2 = ${2}]</insert>
      <insert path="/root">[3 = ${3}]</insert>
    </xmltask>
  </target>


Robert Soesemann wrote:

>Sounds perfect. Thanks for this hint. Did you every do something like
>this? Do you have sample snippets ;-)
>
>Best regards,
>
>Robert
>
>-----Original Message-----
>From: Brian Agnew [mailto:[EMAIL PROTECTED]
>Sent: Freitag, 3. Dezember 2004 16:03
>To: Ant Users List
>Subject: Re: Split XML file into seperate files with XSLT and ANT
>
>
>You can use xmltask with the <call> instruction. See 
>http://www.oopsconsultancy.com/software/xmltask
>
>Robert Soesemann wrote:
>
>  
>
>>Hello,
>>
>>I don't know if there is a standard way to do this, but maybe you have 
>>an idea.
>>
>>I have many XML files which hold multiple XML fragments of a specific 
>>type <contentitem>..</contentitem> For an easy import of those 
>>seperate contentitems into a CMS it would be better to split those 
>>fragments up into different file (one contentitem per file).
>>
>>As I am doing this inside an ant pipeline, I wonder if there is an 
>>elegant way to do this with a mixture of XSLT and other file tasks?
>>
>>Can you help,
>>
>>Robert
>>--
>>Robert Sösemann
>>Associate, Technology | Sapient
>>
>>Kellerstr. 27
>>81667 München, Deutschland
>>Tel.: +49 89/552 987-143
>>Mobil: +49 162/2773-143
>>Fax: +49 89/552 987-100
>>Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>>
>>
>> 
>>
>>    
>>
>
>  
>

-- 
Brian Agnew                  http://www.oopsconsultancy.com
OOPS Consultancy Ltd         brian @ oopsconsultancy.com
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to