xsl-list
[Top] [All Lists]

RE: calling templates

2004-06-21 04:51:29

if u have an xml file like this:
<main>
<name>
<desc>
<link></link>
<section></section>
.........(the any number of section an dlink tags in any 
order) </main>

and u had a template match currently in main, how would u do an 
<xsl:apply-templates /> on all the <link> and <section> tags 
but not the 
<name> and <desc> tags?
i thought about <xsl:apply-templates select="link" /> and then 
<xsl:apply-templates select="section" /> but that would do it 
in two groups, 
i would like to apply the template sin the order they appear 
in the xml 
file......
can anyone help
cheers
james walker

If you want to process the elements in the order they appear in the
document then you must use <xsl:apply-templates/> with no select
attribute; this is known as 'push processing' as the elements in the
document are driving the processing order.  If you use
<xsl:apply-templates select="..."/> then this is 'pull processing' as
the stylesheet is driving the processing order which means elements
could be processed out of document order.

If you want to process certain children of your <main> element, but not
others, and ensure document order is kept, then you will need to use
<xsl:apply-templates/> within your <main> matching template, and add a
'no-op' template for <name> and <desc>:

<xsl:template match="name|desc"/>

You may need to be more specific in your match pattern if the elements
appear in other structures in your source (as they are quite generic
names):

<xsl:template match="main/name|main/desc"/>

cheers
andrew


<Prev in Thread] Current Thread [Next in Thread>