By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Multiple output files in XSLT 2.0

P: n/a
Hello XSLT-freaks,

I have a source xmlfile that I want to transform to 2 different
xmlfiles.

source.xml:

<books>
<book>
<title>Die Brandmauer</title>
<author>Henning Mankell</author>
</book>
</books>

destination1.xml:

<books>
<book>
<title>Die Brandmauer</title>
</book>
</books>

destination2.xml:

<books>
<book>
<author>Henning Mankell</author>
</book>
</books>

This example may look a bit stupid; is is a constructed sample to
simplify my issue.

I tried to use two of the <xsl:resutl-document>-tags to generate 2
different destination files. But I hat the following problem:

I cannot switch the <result-document> INSIDE the <books> from one
resutl-file to another. It seems to me that I can only assign the
<result-document> to a whole "<books>"-tag.

Am I wrong?

Thanks a lot for any hints!

Bernd

Mar 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a


bl*******@gmx.net wrote:

I have a source xmlfile that I want to transform to 2 different
xmlfiles.

source.xml:

<books>
<book>
<title>Die Brandmauer</title>
<author>Henning Mankell</author>
</book>
</books>

destination1.xml:

<books>
<book>
<title>Die Brandmauer</title>
</book>
</books>

destination2.xml:

<books>
<book>
<author>Henning Mankell</author>
</book>
</books> I tried to use two of the <xsl:resutl-document>-tags to generate 2
different destination files. But I hat the following problem:

I cannot switch the <result-document> INSIDE the <books> from one
resutl-file to another. It seems to me that I can only assign the
<result-document> to a whole "<books>"-tag.


Here is an example that uses modes to create on main output file
automatically and a secondary output file with xsl:result-document

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">
<xsl:apply-templates select="books" />
<xsl:result-document href="bookauthors.xml">
<xsl:apply-templates select="books" mode="copy-author" />
</xsl:result-document>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="@* | node()" mode="copy-author">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="copy-author" />
</xsl:copy>
</xsl:template>

<xsl:template match="book">
<xsl:copy>
<xsl:apply-templates select="@* | title" />
</xsl:copy>
</xsl:template>

<xsl:template match="book" mode="copy-author">
<xsl:copy>
<xsl:apply-templates select="@* | author" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Works fine with me using the latest Java Saxon 8 Basic release and run
from the command line alike

java -jar C:\pathtosaxon\saxon8.jar -o booktitles.xml books.xml
stylesheet.xml

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 26 '06 #2

P: n/a
Hey Martin,

Thanks a lot! That helped!

What I was missing was the knowledge of the "mode" attribute to parse a
block several times. Surrounding that attribute by the
<xsl:result-document> creates different files.
Perfect!

Bernd.

Mar 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.