Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] For-each in XSL

From: "Subbiah" <subbiah@------------>
To:
Date: 8/2/2004 11:24:00 PM
Hi Ken,
Thx you for your explanation. Will need to do some more reading.

regards,
-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] 
Sent: Monday, August 02, 2004 4:15 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] For-each in XSL


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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent