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 September 13th, 2007, 04:24 AM
Registered User
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing the line before in a transform

Hi,

I have been stuck trying to create an XSLT that incrementally references the line before when transforming.

My source content looks like this:

<SourceStuff>
<Element action="Name1"></Element>
<Element action="Name2"></Element>
<Element action="Name3"></Element>
<Element action="Name4"></Element>
<Element action="Name5"></Element>
<Element action="Name6"></Element>
</SourceStuff>

And the end result needs to look like this:

<seqRun>
  <El act="Name1" seq="Start">XX</El>
  <El act="Name2" seq="Name1">XX</El>
  <El act="Name3" seq="Name2">XX</El>
  <El act="Name4" seq="Name3">XX</El>
  <El act="Name5" seq="Name4">XX</El>
  <El act="Name6" seq="Name5">XX</El>
</seqRun>

I can do everything except the seq= part where I do not understand how to reference the name of the element one line higher in the file.

I have tried using variables and some other options but I have not managed to get anything even close. While I have shown the names as Name1..Name6 here the actual names are not sequential.

Would anyone be able to point me in the right direction?

thanks very much
Jim
 
Old September 13th, 2007, 04:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Code:
<xsl:attribute name="seq">
<xsl:choose>
<xsl:when test="count(preceding-sibling::Element)=0">Start</xsl:when>
<xsl:otherwise>
    <xsl:value-of select="preceding-sibling::Element[1]/@action" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
/- Sam Judson : Wrox Technical Editor -/
 
Old September 13th, 2007, 06:02 AM
Registered User
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Awesome Sam, thank you very much for your assistance.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
Reading a string from line by line vaidyapragati ASP.NET 2.0 Professional 1 May 3rd, 2007 08:43 AM
Transform multilined element value to one line ypomonh XSLT 2 April 27th, 2007 08:32 AM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM





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