[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: listing elements & sub-elements in a seqence - sk

Subject: RE: 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
session elements
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"/>


<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:   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)] |
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 match="section[subsection]">

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/>  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/>  will become 6. Subsection title (pg 6)
and so on?


All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine 

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.