event-based template matching?

Discussion in 'XML' started by brice, Jul 10, 2003.

  1. brice

    brice Guest

    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
     
    brice, Jul 10, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Colin Mackenzie, Jul 10, 2003
    #2
    1. Advertising

  3. brice

    brice Guest

    What a simple solution. Thanks, it worked perfectly!

    brice

    "Colin Mackenzie" <> wrote in message news:<bejuqk$lac$>...
    > 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
     
    brice, Jul 10, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    372
    mlimber
    Jul 21, 2006
  2. Joel Goldstick
    Replies:
    1
    Views:
    727
    Arnaud Delobelle
    Aug 31, 2010
  3. JemPower

    Capturing checked event for Template based checkbox.

    JemPower, Oct 30, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    180
    JemPower
    Oct 30, 2003
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    237
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    231
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page