event-based template matching?

B

brice

Hello,

I am using using the following code to transform a memo xml file. I am
using Internet Explorer 6.0 to transform and view the file as HTML.

<!-- ***** BEGIN XML ***** -->
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<MEMO ID="1">
<AUTHOR ID="1">
<NAME>Mickey Mouse</NAME>
<DEPARTMENT>Marketing</DEPARTMENT>
</AUTHOR>
<HEADER>
<TITLE>New Campaign</TITLE>
<DATE-CREATED>7/10/03</DATE-CREATED>
</HEADER>
<SECTION ID="1">
<PARAGRAPH>
This is an important memo to address the following items:
</PARAGRAPH>
<LIST>
<ITEM>Important item one.</ITEM>
<ITEM>Important item two.</ITEM>
<ITEM>Important item three.</ITEM>
</LIST>
<PARAGRAPH>
After this is done, please address these items:
</PARAGRAPH>
<LIST>
<ITEM>More stuff one.</ITEM>
<ITEM>More stuff two.</ITEM>
<ITEM>More stuff three.</ITEM>
</LIST>
</SECTION>
</MEMO>
<!-- ***** END XML ***** -->

<!-- ***** BEGIN XSL ***** -->
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html"/>

<xsl:template match="/MEMO">
<HTML>
<HEAD>
<TITLE>XML Test</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates select="HEADER"/>
<xsl:apply-templates select="AUTHOR"/>
<xsl:apply-templates select="SECTION"/>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="HEADER">
<H2><xsl:value-of select="./TITLE"/></H2>
Date: <xsl:value-of select="./DATE-CREATED"/><BR/>
</xsl:template>

<xsl:template match="AUTHOR">
Author: <xsl:value-of select="./NAME"/><BR/>
Department: <xsl:value-of select="./DEPARTMENT"/><BR/>
</xsl:template>

<xsl:template match="SECTION">
<xsl:apply-templates select="PARAGRAPH"/>
<xsl:apply-templates select="LIST"/>
</xsl:template>

<xsl:template match="PARAGRAPH">
<P><xsl:value-of select="."/></P>
</xsl:template>

<xsl:template match="LIST">
<P>
<xsl:for-each select="./ITEM">
- <xsl:value-of select="."/><BR/>
</xsl:for-each>
</P>
</xsl:template>

</xsl:stylesheet>
<!-- ***** END XSL ***** -->

<!-- ***** BEGIN HTML RESULT ***** -->
New Campaign

Date: 7/10/03
Name: Mickey Mouse
Department: Marketing

This is an important memo to address the following items:

After this is done, please address these items:

- Important item one.
- Important item two.
- Important item three.

- More stuff one.
- More stuff two.
- More stuff three.

<!-- ***** END HTML RESULT ***** -->

I understand why this transforms this way, but I want to be able to
tweak this and process each of the elements under the SECTION element
as they appear. In other words:

1.) The first paragraph would be transformed and output.
2.) Then the first list items would be transformed and output beneath
the first paragraph.
3.) Then the second paragraph would be output below this.
4.) Then the second list items would be output below this.

Can anyone help me with this?

Thanks in advance,

brice
 
C

Colin Mackenzie

In your match for SECTION do

<xsl:template match="SECTION">
<xsl:apply-templates/>
</xsl:template>

and all children will be macthed in the order they occur

Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top