RE: [xsl] listing elements & sub-elements in a seqence - skiping elemts if sub-elemts are present

Subject: RE: [xsl] listing elements & sub-elements in a seqence - skiping elemts if sub-elemts are present
From: cknell@xxxxxxxxxx
Date: Tue, 25 Jul 2006 08:50:15 -0400
xsl:for-each will, in the absence of a child xsl:sort element, output the nodes in the same order as they appeared in the original document.

xsl:apply-templates will also output nodes in the sames order as they appeared in the original document.

This expression: "//Session/Section[not(SubSection)] | //Session/Section/SubSection"

signifies the union of the sets of all Session elements anywhere in the document having a Section child element, which in turn either has or does not have a Subsection child element.

In other words, it includes all Session elements having a Section child element. Nothing in the expression indicates anything about the order in which the output will be returned, therefor it will come back in the same order as in the original document.

This expression is equivalent to the one above, more compact, and less likely to lead you into thinking you have done something when in fact you haven't. : "//Session/Section"


If you use:
 
<xsl:apply-templates select="//Session/Section" />

you will get the same output as:
 
<xsl:for-each select="//Section[not(SubSection)] | //Section/SubSection"/>

or 

<xsl:for-each select="//Session/Section" />

The advantage to the former is that it begins to move your thinking away from the procedural toward the declarative nature of XSLT and removes cruft that could be misleading you.

Without seeing your input document and an example of the desired output (not a description of the desired output as you have provided), it's hard to offer more specific advice.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Karl <call14@xxxxxxxxx>
Sent:     Tue, 25 Jul 2006 11:45:50 +0100 (BST)
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  [xsl] listing elements & sub-elements in a seqence - skiping elemts if sub-elemts are present

Thanks David / Charles for the reply and yes the code <xsl:for-each
select="//Session/Section[not(SubSection)] |
//Session/Section/SubSection"/> worked. Infact I did tried this
before writing to the list but an spelling err from my side made me
to think the code was wrong. Sorry. 

But after seeing Chris's reply, I have a q

<xsl:for-each select="//Section[not(SubSection)] |
//Section/SubSection"/>
is definetly giving me the correct order of section and subsection
info that i wanted.

will charles's suggestion,

<xsl:template match="section[not(subsection)]">
 ...
</xsl:template>

& 

<xsl:template match="section[subsection]">
 ...
</xsl:template>

Then simply apply-templates, WILL GIVE THE RESULTS IN SAME ORDER as
that of for-each? [Pls note my actual reqmt is to generate pages with
specific name order and list them in specific order with links etc.
But I have simplified here to get the essence that I expect to
acheive] i.e,

<Section/>  will become  1.Section title in list + creat pg 1
<Section/>  
<Section/>  will become list num 3.Section title & pg 3

<Section>  ** [No pagebreaks/pagenums SINCE IT HAS <subsection> 
 <SubSection/>  So, this become 4. Subsection title (pg 4) 
 <SubSection/>  
 <SubSection/>  will become 6. Subsection title (pg 6)
<Section>  
and so on?

Thanks
karl


	
	
		
___________________________________________________________ 
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine 
http://uk.docs.yahoo.com/nowyoucan.html

Current Thread