drame(_at_)informatik(_dot_)hu-berlin(_dot_)de wrote:
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?
You need to restructure your stylesheet alike this
<xsl:template match="/">
<xsl:result-document href="file1.xml">
<xsl:for-each select="groups/group/title[matches(., '^file 1',
'i')]">
<contentOfTitleElmt>
<xsl:value-of select="."/>
</contentOfTitleElmt>
</xsl:for-each>
</xsl:result-document>
<xsl:result-document href="file2.xml">
<xsl:for-each select="groups/group/title[matches(., '^file 2',
'i')]">
<contentOfTitleElmt>
<xsl:value-of select="."/>
</contentOfTitleElmt>
</xsl:for-each>
</xsl:result-document>
<xsl:result-document href="file3.xml">
<xsl:for-each select="groups/group/title[not(matches(., '^file
1', 'i') and matches(., '^file 2', 'i'))]">
<contentOfTitleElmt>
<xsl:value-of select="."/>
</contentOfTitleElmt>
</xsl:for-each>
</xsl:result-document>
</xsl:template>
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--