Multiple Result Trees

Subject: Multiple Result Trees
From: "Richard Lander" <rlander@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Jul 1999 11:01:33 -0400
Hello,

I've been thinking about the possibility of an XSLT transformation to multiple
result trees. I see that it is on the list for future version of XSLT, but was
wondering if a 'kludge' was possible now through the use of modes. I've
constructed a little demo, illustrating my idea, which may already be old news,
but it appeared as a novel idea to me.

I realize that what I've done is not really multiple trees, but it does become
multiple trees if you use a file-spliter to split out the two parts. I hope this
demo is of some help to someone. I guess I could have also simply made an
identity transform with mode="xml", saving me from making all the virtually
identical mode="xml" rules, but I'll likely want to actually transfrom the XML
output later on. For all its worth ....

Rich'd.

P.S. I do realize that output.xml isn't a well-formed document, as it is missing
a root element, but the point remains the same.

*test.xml*

<doc>
<block>
<PARA>This part is a block, including a <WEBLINK
url="http://pdbeam.uwaterloo.ca/~rlander/";>Website</WEBLINK></PARA>
</block>

<block>
<PARA frank="345">Another block, with an <KEYWORD>important</KEYWORD>
keyword.</PARA>
</block>
</doc>

*output.xml*

<HTML>
<DIV class="block">
<P>This part is a block, including a <A
href="http://pdbeam.uwaterloo.ca/~rlander/";>Website</A>
</P>
</DIV>

<DIV class="block">
<P>Another block, with an <EM>important</EM> keyword.</P>
</DIV>
</HTML>


<doc>
<block>
<PARA>This part is a block, including a <WEBLINK
url="http://pdbeam.uwaterloo.ca/~rlander/";>Website</WEBLINK>
</PARA>
</block>

<block>
<PARA frank="345">Another block, with an <KEYWORD>important</KEYWORD>
keyword.</PARA>
</block>
</doc>

*test.xsl*

<?xml version='1.0' standalone='yes'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/XSL/Transform/1.0'
indent-result="yes">

<xsl:template match='/'>
 <xsl:apply-templates/>
</xsl:template>


<xsl:template match='doc'>
 <HTML>
 <xsl:apply-templates mode="html"/>
 </HTML>
 <xsl:text>


</xsl:text>
 <xsl:copy>
 <xsl:apply-templates mode="xml"/>
 </xsl:copy>
</xsl:template>

<xsl:template match='block' mode="html">
 <DIV class="block">
 <xsl:apply-templates mode="html"/>
 </DIV>
</xsl:template>

<xsl:template match='block' mode="xml">
 <xsl:copy>
 <xsl:apply-templates mode="xml"/>
 </xsl:copy>
</xsl:template>

<xsl:template match='PARA' mode="html">
 <P>
 <xsl:apply-templates mode="html"/>
 </P>
</xsl:template>

<xsl:template match='PARA' mode="xml">
 <xsl:copy>
 <xsl:apply-templates mode="xml" select="*|@*|text()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match='KEYWORD' mode="html">
 <EM>
 <xsl:apply-templates/>
 </EM>
</xsl:template>

<xsl:template match='KEYWORD' mode="xml">
 <xsl:copy>
 <xsl:apply-templates/>
 </xsl:copy>
</xsl:template>

<xsl:template match='WEBLINK' mode="html">
 <A href="{@url}">
 <xsl:apply-templates/>
 </A>
</xsl:template>

<xsl:template match='WEBLINK' mode="xml">
 <xsl:copy>
 <xsl:apply-templates mode="xml" select="*|@*|text()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match='@*' mode="xml">
 <xsl:copy>
 <xsl:apply-templates select="@*"/>
 </xsl:copy>
</xsl:template>


</xsl:stylesheet>


Richard Lander
relander at uwaterloo.ca
http://pdbeam.uwaterloo.ca/~rlander/

Professional XML Authoring
http://www.on-line-learning.com/




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


Current Thread