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 19th, 2014, 04:09 AM
Registered User
 
Join Date: Feb 2014
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy XSLT with sequence row number

Hi All,

Am new to XSLT, in my project we have requirement of XML to XML conversion

1. Have XML
Code:
<?xml version="1.0"?>
<OpsmanDRS>
	<?xml-multiple dataOpsmanDRS?>
	<dataOpsmanDRS>
		<drsNumber>YPDB0510000001</drsNumber>
		<?xml-multiple deliveryDtlsDO?>
		<deliveryDtlsDO>
			<consignmentNumber>F991B4300018</consignmentNumber>
		</deliveryDtlsDO>
		<deliveryDtlsDO>
			<consignmentNumber>F991B4300022</consignmentNumber>
		</deliveryDtlsDO>
	</dataOpsmanDRS>
	<dataOpsmanDRS>
		<drsNumber>DS9140000002</drsNumber>
		<?xml-multiple deliveryDtlsDO?>
		<deliveryDtlsDO>
			
		</deliveryDtlsDO>
		<deliveryDtlsDO>
			<consignmentNumber>S991B0000223</consignmentNumber>
			
		</deliveryDtlsDO>
	</dataOpsmanDRS>
</OpsmanDRS>
2. But result XML should be as below

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
	<FORM name="Delivery">
		<row no="0">
			<FL val="Consignment No">S02400001310</FL>
			<FL val="drsNumber">AUT751004</FL>
		</row>
		<row no="1">
			<FL val="Consignment No">S02400001333</FL>
			<FL val="drsNumber">AUT751004</FL>
			
		</row>
	</FORM>
</root>
please help me to write XSLT for below line

<row no="1">

here issue with incremental value in no attribute of <row>
 
Old February 19th, 2014, 04:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Take a look at the position() function. Or at xsl:number. You will find plenty of examples in my book.

If you have further questions, it's a good idea to show your attempts so far, and to explain where you are stuck. Then we can see what help you need.

Don't expect people here to write your code for you.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 19th, 2014, 05:19 AM
Registered User
 
Join Date: Feb 2014
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Take a look at the position() function. Or at xsl:number. You will find plenty of examples in my book.

If you have further questions, it's a good idea to show your attempts so far, and to explain where you are stuck. Then we can see what help you need.

Don't expect people here to write your code for you.
Thanks mhkay for your quick reply....

have created XSL as below
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes" />
	<xsl:strip-space elements="*" />
	<xsl:template match="/OpsmanDRS">
		<root>
			<FORM name="Delivery">
				<xsl:for-each select="/OpsmanDRS/dataOpsmanDRS">

				<xsl:for-each select="current()/deliveryDtlsDO">
						<row>
		<xsl:attribute name="no"><xsl:number/></xsl:attribute>
							
	<FL val="Runsheet Id">		<xsl:value-of select="../drsNumber" />
							</FL>
<FL val="Consignment no"><xsl:value-of select="consignmentNumber" />
							</FL>
						</row>
					</xsl:for-each>

				</xsl:for-each>

			</FORM>
		</root>
	</xsl:template>

</xsl:stylesheet>
and generating the output as

Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
	<FORM name="Delivery">
		<row no="1">
			<FL val="Runsheet Id">YPDB0510000001</FL>

			<FL val="Consignment no">F991B4300018</FL>
		</row>
		<row no="2">
			<FL val="Runsheet Id">YPDB0510000001</FL>
			<FL val="Consignment no">F991B4300022</FL>
		</row>
		<row no="3">
			<FL val="Runsheet Id">YPDB0510000001</FL>
			<FL val="Consignment no">F991B4300047</FL>
		</row>
		<row no="1">
			<FL val="Runsheet Id">DS9140000002</FL>

			<FL val="Consignment no">S991B0000237</FL>
		</row>
		<row no="2">
			<FL val="Runsheet Id">DS9140000002</FL>
			<FL val="Consignment no">S991B0000223</FL>
		</row>
		<row no="1">
			<FL val="Runsheet Id">DS914000018</FL>
			<FL val="Consignment no">F991B0000106</FL>
		</row>
		<row no="2">
			<FL val="Runsheet Id">DS914000018</FL>
			<FL val="Consignment no">F991B0000058</FL>
		</row>
	</FORM>
</root>
HTML Code:
problem here is <row no="1"> is  repeating again.... can just help me to correct it.....

it may looks silly ..but am a just started to implement XSLT...
 
Old February 19th, 2014, 10:23 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Try
Code:
<xsl:for-each select="deliveryDtlsDO">
    <row>
        <xsl:attribute name="no"><xsl:number level="any"/></xsl:attribute>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
[email protected] (February 20th, 2014)
 
Old February 20th, 2014, 05:25 AM
Registered User
 
Join Date: Feb 2014
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up

Thank you.....it worked...





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a line number/Row number- need to use it for page breaks naijacoder XSLT 7 September 27th, 2009 09:42 PM
To retrieve a row by giving row number prad_a MySQL 1 March 22nd, 2007 11:20 PM
Number Sequence Generator Peso SQL Server 2000 4 May 11th, 2006 01:36 PM
How to read Hard Disk sequence number by Java? Edward King J2EE 1 September 19th, 2005 03:29 PM
sequence number for online receipt preston2003 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 April 25th, 2005 02:02 AM





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