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

Re: For-each in XSL

Subject: Re: For-each in XSL
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 02 Aug 2004 17:14:40 -0400
for each in xslt
At 2004-08-02 15:17 -0500, Subbiah wrote:
My XML -
<location id="texas">
  <name>Jim</name>
        <children>tommy</children>
        <children>pam<children>
        <children>sam<children>
   </name>
</location>

I need to get to print the chilrens name in a page on a new line

A common requirement.


 The number of children can vary so I need to get all the children, when I
use a for-each tag I am not able to access it.

You need to review some basic principles of XSLT that should be easily available in online resources.


When you are processing the template supplied with an <xsl:for-each> instruction, your current node list is the collection of nodes addressed in the select= attribute, and the template is processed for adding to the result tree as many times as there are members in the current node list. Each time the template is processed the next node in document order of the current node list becomes the current node.

<xsl:for-each select = "location/name/children">
                <fo:block text-align="left">
                <xsl:value-of select = "location/name/children"/>

Above you are not considering that your current node is already <children> and you only need the value of the current node, addressed using ".". Though best practice is to use <xsl:apply-templates/> so as to allow your stylesheet to be imported by other stylesheets for specialization purposes. Doing this would engage the built-in template rules for the text of the <children> element.


                </fo:block>
        </xsl:for-each>

So you would have:


        <xsl:for-each select = "location/name/children">
                <fo:block text-align="left">
                        <xsl:apply-templates/>
                </fo:block>
        </xsl:for-each>

I hope this helps.

................... Ken

--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread
  • For-each in XSL
    • Subbiah - 2 Aug 2004 20:24:03 -0000
      • cking - 2 Aug 2004 21:08:44 -0000
        • cking - 2 Aug 2004 21:13:24 -0000
      • G. Ken Holman - 2 Aug 2004 21:15:18 -0000 <=
        • Subbiah - 2 Aug 2004 23:24:29 -0000
      • xptm - 2 Aug 2004 21:15:53 -0000
        • Subbiah - 2 Aug 2004 23:24:44 -0000

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.