Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > event-based template matching?

Reply
Thread Tools

event-based template matching?

 
 
brice
Guest
Posts: n/a
 
      07-10-2003
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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
 
Reply With Quote
 
 
 
 
Colin Mackenzie
Guest
Posts: n/a
 
      07-10-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xslutput 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



 
Reply With Quote
 
 
 
 
brice
Guest
Posts: n/a
 
      07-10-2003
What a simple solution. Thanks, it worked perfectly!

brice

"Colin Mackenzie" <(E-Mail Removed)> wrote in message news:<bejuqk$lac$(E-Mail Removed)>...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
r H2 deduce deduce template argument of a template class inheritingfrom a non template base? nguillot C++ 5 03-08-2009 05:56 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments