xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] For-each in XSL


Subject: Re: [xsl] For-each in XSL
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 02 Aug 2004 17:14:40 -0400

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
  • Re: [xsl] For-each in XSL, (continued)
    • cking - Mon, 2 Aug 2004 22:35:33 +0200
      • cking - Mon, 2 Aug 2004 23:11:42 +0200
    • xptm - Mon, 02 Aug 2004 22:12:13 +0100
      • Subbiah - Mon, 2 Aug 2004 18:23:54 -0500
    • G. Ken Holman - Mon, 02 Aug 2004 17:14:40 -0400 <=
      • Subbiah - Mon, 2 Aug 2004 18:23:38 -0500
Keywords
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor