event-based template matching?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brice

    #1

    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>Mar keting</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>Importa nt item one.</ITEM>
    <ITEM>Importa nt item two.</ITEM>
    <ITEM>Importa nt 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:styleshe et 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:valu e-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="PARAGRA PH"/>
    <xsl:apply-templates select="LIST"/>
    </xsl:template>

    <xsl:template match="PARAGRAP H">
    <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

    #2
    Re: event-based template matching?

    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" <bricemason@hot mail.com> wrote in message
    news:50404b7a.0 307100510.74d00 3b@posting.goog le.com...[color=blue]
    > 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>Mar keting</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>Importa nt item one.</ITEM>
    > <ITEM>Importa nt item two.</ITEM>
    > <ITEM>Importa nt 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:styleshe et 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:valu e-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="PARAGRA PH"/>
    > <xsl:apply-templates select="LIST"/>
    > </xsl:template>
    >
    > <xsl:template match="PARAGRAP H">
    > <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[/color]


    Comment

    • brice

      #3
      Re: event-based template matching?

      What a simple solution. Thanks, it worked perfectly!

      brice

      "Colin Mackenzie" <colin@elecmc.c om> wrote in message news:<bejuqk$la c$1@newsg3.svr. pol.co.uk>...[color=blue]
      > 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[/color]

      Comment

      Working...