multiple pass with XSL on same XML file

A

andrew_nuss

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.
 
A

A. Bolmarcich

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top