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 25th, 2009, 11:19 AM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default how to contro current() when printing values

I am trying to print values based on the first and last position. For example here is my XML

<?xml version="1.0"?>
<ss>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
<id>
<picture>image.jpg</picture>
<text>sample text </text>
</id>
</ss>


here is my xslt. Basically I am trying to seperate the first node and the last node from the rest of the output. Can someone tell me if I am doing this correctly or do I need to add or remove anything?

<xsl:for-each select="//id">
<xsl:value-of select="count(//id)"/>
<xsl:if test="current() = 1">
This is the first node
<xsl:value-of select="picture"/>
<xsl:value-of select="text"/>
</xsl:if>
<xsl:value-of select="picture"/>
<xsl:value-of select="text"/>
<xsl:if test="current() = last">
This is the last node
<xsl:value-of select="picture"/>
<xsl:value-of select="text"/>
</xsl:if>
</xsl:for-each>
 
Old February 25th, 2009, 11:43 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

current() returns a node and not a number. So doing
current() = 1
does not make sense, I guess you want
position() = 1
respectively
position() = last()
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
having issue printing child values by comparing parents value eruditionist XSLT 4 January 7th, 2009 02:34 AM
help in inheritting user contro properties sonug95 VS.NET 2002/2003 1 July 27th, 2007 06:12 AM
Printing values vinay_shrivastava03 .NET Framework 1.x 1 April 23rd, 2007 03:45 AM
Printing element's values problem !!! engergojita XSLT 1 April 12th, 2007 03:30 AM
How to pass values from one XSLT to another contro sani723 XSLT 2 March 27th, 2007 05:43 AM





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