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 May 8th, 2012, 03:25 PM
Authorized User
 
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.
 
Old May 8th, 2012, 03:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
The Following User Says Thank You to mhkay For This Useful Post:
JohnKiller (May 8th, 2012)
 
Old May 8th, 2012, 03:48 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thank you so much, Michael. It is solved.





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





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