[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: conditional multiple outputs

Subject: Re: conditional multiple outputs
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Thu, 14 May 2009 12:52:37 +0200
Re:  conditional multiple outputs
As almost always, the error message is correct.

You basically loop through all <title> in document order and try to
create a new document for each <title>. So the second time you see a
title with "file 1" your XSL tries to create another file1.xml - boom!

Try it the other way round:

<xsl:result-document href="file1.xml">
  <xsl:for-each select="title[starts-with(., 'file 1')]">
    <xsl:copy-of select="."/>
  </
</
<xsl:result-document href="file2.xml">
  <xsl:for-each select="title[starts-with(., 'file 2')]">
    <xsl:copy-of select="."/>
  </
</
<xsl:result-document href="file3.xml">
  <xsl:for-each select="title[starts-with(., 'file 3')]">
    <xsl:copy-of select="."/>
  </
</

- Michael M|ller-Hillebrand

Am 14.05.2009 um 12:35 schrieb drame@xxxxxxxxxxxxxxxxxxxxxxx:

Hi,

I am trying to generate multiple output files in a single template
(see
xsl file below). The scenario is the following:

1. I read elements <title> one after the other from a input file
"content.xml"
2. if the text of the element <title> begins with the substring
"file 1",
then copy the element to the output file file1.xml, if it begins with
"file 2" then output to file2.xml, else copy the element to file3.xml.

The processor I use is Saxon B on .NET and XLST version is 2.0. But my
script does not work since I always have following error message:

E:\test\xsl>Transform -s:"e:\test\xsl\content.xml"
-xsl:"e:\test\xsl\import.xsl
Error at xsl:choose on line 8 of file:///e:/test/xsl/import.xsl:
 XTDE1490: Cannot write more than one result document to the same
URI, or
write to a URI
 that has been read: file:/E:/test/xsl/file2.xml
Transformation failed: Run-time errors were reported



Here are the script and the input file content.xml:

<!--content.xml-->
<?xml version="1.0" encoding="UTF-8"?>
<groups>
       <group>
               <title>file 1 xxx </title>
               <title>file 2 efg </title>
       </group>
       <group>
               <title>file 2 xxx </title>
               <title>file 3 abc </title>
       </group>
       <group>
               <title>file 1 abc </title>
               <title>file 3 xyz </title>
       </group>
       <group>
               <title>file 2 zzz </title>
               <title>file 2 ihk </title>
       </group>
</groups>



<!--multipleOutput.xsl-->
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
       <xsl:output method="xml" indent="yes" encoding="utf-8"/>
       <xsl:template name="test" match="/">
               <xsl:for-each select="groups/group">
                       <xsl:for-each select="title">
                               <xsl:variable
name="textOfTheElementTitle"
select="substring(./text(), 1, 6)"/>
                               <xsl:choose>
                                       <xsl:when
test="matches($textOfTheElementTitle,
'file 1', 'i')">
                                               <xsl:result-document
href="file1.xml">

<contentOfTitleElmt>

<xsl:value-of
select="./text()"/>
                                                       </
contentOfTitleElmt>
                                               </xsl:result-document>
                                       </xsl:when>
                                       <xsl:when
test="matches($textOfTheElementTitle,
'file 2', 'i')">
                                               <xsl:result-document
href="file2.xml">

<contentOfTitleElmt>

<xsl:value-of
select="./text()"/>
                                                       </
contentOfTitleElmt>
                                               </xsl:result-document>
                                       </xsl:when>
                                       <xsl:otherwise>
                                               <xsl:result-document
href="file3.xml">

<contentOfTitleElmt>

<xsl:value-of
select="./text()"/>
                                                       </
contentOfTitleElmt>
                                               </xsl:result-document>
                                       </xsl:otherwise>
                               </xsl:choose>
                       </xsl:for-each>
               </xsl:for-each>
       </xsl:template>
</xsl:stylesheet>

Does somebody know why it does not work? Should I use another function
than xsl:result-document?

Many thanks in advance,
Regards

Horace

-- _______________________________________________________________ Michael M|ller-Hillebrand: Dokumentations-Technologie Adobe Certified Expert, FrameMaker Lvsungen und Training, FrameScript, XML/XSL, Unicode Blog: http://cap-studio.de/ - Tel. +49 (9131) 28747

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.