Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 8th, 2012, 03:25 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Question How to create a dynamic increment field

In my input XML file, there are maybe several loop blocks, I need to mark these loop as 1, 2, 3,... in the output file. I am using XSLT 2.0.

The input file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<request>
  <dateTime year="2012" month="05"/>
  <telephoneNumber TN="2603732125" >
    <detail value="0" tag="CF"/>
  </telephoneNumber>
  <telephoneNumber TN="2603732136">
    <detail value="B" tag="TXTYP"/>
  </telephoneNumber>
</request>
Output XML should be:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<edi>
<ISA>
  <GS>
    <TS>
      <SLN>
        <SLN02>1</SLN02>
        <SLN05>EA</SLN05>
      </SLN>
      <SI>
         <SI02>RQ</SI02>
         <SI03>2603732136</SI03>
      </SI>
      <SLN>
        <SLN02>2</SLN02>
        <SLN05>EA</SLN05>
      </SLN>
      <SI>
        <SI02>RQ</SI02>
        <SI03>2603732136</SI03>
      </SI>
    </TS>
  </GS>
</ISA>
</edi>
For each telephoneNumber node, I need to create the SLN node, as make the SI02 as the the sequence number from 1. I do not know how to do this in XSLT.

Thank you in advance for any help.
Reply With Quote
  #2 (permalink)  
Old May 8th, 2012, 03:35 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Presumably your code has either an xsl:for-each select="telephoneNumber" or an xsl:apply-templates select="telephoneNumber" somewhere within in. Within the code that processes each telephone number, the position() function gives you the position in that sequence: 1, 2, etc.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
JohnKiller (May 8th, 2012)
  #3 (permalink)  
Old May 8th, 2012, 03:48 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thank you so much, Michael. It is solved.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reset an auto-increment field each month totoune SQL Server 2005 4 April 3rd, 2009 09:31 PM
Auto Increment Field Problem in SQL Server 2000 yes_no ASP.NET 1.0 and 1.1 Professional 4 August 11th, 2008 07:10 AM
SQL Server Identity field won't increment Ron Howerton VB.NET 2002/2003 Basics 8 April 22nd, 2004 12:14 PM
Retrieving Dynamic Field Names tdaustin Classic ASP Basics 4 January 12th, 2004 11:10 AM
Manual Increment MySQL Field cmiller Beginning PHP 4 August 27th, 2003 05:26 PM



All times are GMT -4. The time now is 07:16 PM.


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