multiple pass with XSL on same XML file

Discussion in 'XML' started by andrew_nuss@yahoo.com, Feb 16, 2007.

  1. Guest

    Hi,

    I have simplified my DTD for the purposes of this question. Let's say
    that I have the following tags: <section1>, <section2>, <section3>
    with xsl that uses <xsl:template match="section1"> etc for each
    section tag and corresponding <xsl::template match="blah"> for all of
    the implied subtags.

    Now, lets say I need to concatenate the results of 2 passes thru the
    document, such that I (a) spit out some predefined HTML, (2) make a
    pass thru the XML file using one interpretation of each section and
    concatenate to the HTML already output, (3) spit out some more HTML,
    (3) make a second pass thru the XML file using a different
    interpretation of each section and concatenate to HTML already output,
    and (4) spit out my final predefined HTML section.

    My question is how with <xsl:template match ...> do I have different
    xsl:template tags for the same sections and ask the transformation to
    use the appropriate one. Can anyone give me some sample xsl code?

    Thanks,
    Andy

    P.S. I'm wanting to identify my header sections and create a left nav
    for the final HTML file, with the
    left nav being the results of the first transformation and the content
    being the result of the second transformation, all to the same output
    HTML file.
     
    , Feb 16, 2007
    #1
    1. Advertising

  2. On 2007-02-16, <> wrote:
    > Hi,
    >
    > I have simplified my DTD for the purposes of this question. Let's say
    > that I have the following tags: <section1>, <section2>, <section3>
    > with xsl that uses <xsl:template match="section1"> etc for each
    > section tag and corresponding <xsl::template match="blah"> for all of
    > the implied subtags.
    >
    > Now, lets say I need to concatenate the results of 2 passes thru the
    > document, such that I (a) spit out some predefined HTML, (2) make a
    > pass thru the XML file using one interpretation of each section and
    > concatenate to the HTML already output, (3) spit out some more HTML,
    > (3) make a second pass thru the XML file using a different
    > interpretation of each section and concatenate to HTML already output,
    > and (4) spit out my final predefined HTML section.
    >
    > My question is how with <xsl:template match ...> do I have different
    > xsl:template tags for the same sections and ask the transformation to
    > use the appropriate one. Can anyone give me some sample xsl code?
    >
    > Thanks,
    > Andy
    >
    > P.S. I'm wanting to identify my header sections and create a left nav
    > for the final HTML file, with the
    > left nav being the results of the first transformation and the content
    > being the result of the second transformation, all to the same output
    > HTML file.


    Use the mode attribute of xsl:template to have different templates
    with the same match pattern. For example have

    <xsl:template match="section1" mode="leftnav">
    <!-- template body for the left nav; uses -->
    <!-- <xsl:apply-templates mode="leftnav"/> -->
    </xsl:template>

    and
    <xsl:template match="section1">
    <!-- template body for the second transform -->
    </xsl:template>

    In the template body that produces the whole output document use

    <!-- spit out some predefined HTML -->
    <xsl:apply-templates select="pass1nodeset" mode="leftnav"/>
    <!-- spit out some more HTML -->
    <xsl:apply-templates select="pass2nodeset"/>
    <!-- spit out some more HTML -->

    Where "pass1nodeset" and "pass2nodeset" are the node sets you
    apply the templates to for the two passes.
     
    A. Bolmarcich, Feb 17, 2007
    #2
    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:
    3,613
    A. Bolmarcich
    May 27, 2005
  2. gabor
    Replies:
    19
    Views:
    1,133
    Steve Holden
    May 31, 2005
  3. Jp Calderone
    Replies:
    7
    Views:
    1,193
    Mike Meyer
    May 28, 2005
  4. Jp Calderone
    Replies:
    0
    Views:
    463
    Jp Calderone
    May 27, 2005
  5. Jp Calderone
    Replies:
    4
    Views:
    453
    gabor
    May 31, 2005
Loading...

Share This Page