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 August 11th, 2010, 09:02 AM
Registered User
 
Join Date: Aug 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Line Counter/Integer Variable

Hi,

I am reading in an XML file and writing out a flat text file. The last line of the flat file has to contain the number of records written out.

How do I set up a integer variable and add to it everytime I write a new row out? Or is there a better way to do this?

Thanks.
RR.
 
Old August 11th, 2010, 09:11 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You can count nodes (or items in general with XSLT/XPath 2.0) with XSLT/XPath, the count function allows that and the xsl: number instruction allows that. If you simply map some input nodes to some output lines than using count on those nodes should suffice, if it is more complicated then you might want to create a temporary output result and count nodes in that result.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 11th, 2010, 09:12 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't modify variables in XSLT - its a functional programming language.

You'll need to count the number of times you output a record some other way, but without knowing something about your input XML and the XSLT you are using this is impossible to help you further on.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 11th, 2010, 09:44 AM
Registered User
 
Join Date: Aug 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to get this done using XSLT 1.0.

The input is an 834 X12 (EDI) file in XML format. Don't know if that helps much. The output is flat file fixed.

I cannot count the number of nodes as not each node will be written out.

I might be able to switch to 1.2, but I am trying to stay with 1.0 for possible support reasons.

Thanks again.
RR.
 
Old August 11th, 2010, 09:47 AM
Registered User
 
Join Date: Aug 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, I might be able to count one partictular node. I am only using one loop, so counting how many times that loop exists may help.

Thanks again!
RR
 
Old August 11th, 2010, 09:53 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

There is no such thing as XSLT 1.2 - I assume you mean XSLT 2.0.

And no, knowing it is 834 X12 file doesn't help at all unsurprisingly.

You can count nodes based on some form of criteria, the exact same criteria that you are using to determine if a node should be output.

e.g. count(/root/node[value='output'])

Alternatively you will have to create your output in a temporary variable (this is easier in XSLT 2.0) and then count how many nodes are in it before outputting the variable, e.g.

Code:
<xsl:variable name="output">
  <xsl:apply-templates select="nodes"/>
</xsl:variable>

<xsl:variable name="outputCount" select="count($output/nodes)"/>

<xsl:value-of select="$output"/>
<xsl:valur-of select="$outputCount"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
hit counter (integer length from bytes to mega bytes) sandeepgreaternoida BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 0 May 9th, 2009 03:05 AM
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
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
Rows/Line Counter jmss66 Classic ASP Basics 5 July 4th, 2003 11:05 AM





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