Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2009, 06:46 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default How to get the value of first 3 nested nodes using xsl:for-each

This is my XML

<?xml version="1.0"?>
<detail>
<title>
<link>a</link></title>
<title>
<link>b</link></title>
<title>
<link>c</link></title>
<title>
<link>d</link></title>
<title>
<link>e</link></title>
</detail>


This is my XSL
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//title">
<xsl:value-of select="link"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


This gives me an output "a b c d e" but I only need to be able to print a b and c only and not all of them. How do I control my xsl:for-each loop?
 
Old February 11th, 2009, 07:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

select="(//title)[4 > position()]"
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 11th, 2009, 07:42 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks that worked
 
Old February 25th, 2009, 03:54 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

This looks similar to what I'm trying to achieve. From the narrative, I need to print out the last nodes which determined by a variable.

Basically the opposite of what eruditionist http://p2p.wrox.com/images/statusicon/user_offline.gif was trying to achieve. I need the last few nodes

Last edited by rabs; February 25th, 2009 at 04:01 PM.. Reason: change
 
Old February 25th, 2009, 04:04 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

dont worry, figured it out.

I used this - <xsl:for-each select="$dcr[$numPr+1 &lt; position()]">
</xsl:for-each>
 
Old February 25th, 2009, 04:18 PM
Authorized User
 
Join Date: Feb 2009
Posts: 43
Thanks: 10
Thanked 0 Times in 0 Posts
Default

I spoke too soon. This...

Code:
<xsl:for-each select="$dcr[$numPr+1 &lt; position()]">
                  </xsl:for-each>
did not work. it returns all the nodes





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL multiple files in table (nested for-each ?) pedoublety XSLT 5 August 21st, 2007 08:00 AM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
Handling recursive XML Nodes using XSL RichaM XSLT 5 June 21st, 2005 02:45 PM
XSL-help-sum of nodes baed on a condition skumar80 XSLT 2 November 8th, 2003 10:08 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.