473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

event-based template matching?

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:output 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
Jul 20 '05 #1
2 1741
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

--
Colin Mackenzie
XML Consultant
Electronic Media Consultants Ltd
Web: http://www.elecmc.com
"brice" <br********@hotmail.com> wrote in message
news:50*************************@posting.google.co m...
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:output 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

Jul 20 '05 #2
What a simple solution. Thanks, it worked perfectly!

brice

"Colin Mackenzie" <co***@elecmc.com> wrote in message news:<be**********@newsg3.svr.pol.co.uk>...
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
9
by: VK | last post by:
My original idea of two trains, however pictural it was, appeared to be wrong. The truth seems to be even more chaotic. IE implements its standard down-up model: any mouse event goes from the...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
3
by: Melissa | last post by:
What specifically causes the Format event of a report's section to fire? Thanks! Melissa
6
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.