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 | Calendar | 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 July 17th, 2008, 07:32 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL: Count = Count + 1

I am creating the ASCII file using XSL.

From XML, when ever i am finding the value from both xml file (Invoice/InvoiceItem/Set/Att[@Id='LC']) AND (Inventory/Item/Parts@Id="myParts")

i will harcode as "HEADING".

At the end I need to find the total number of "HEADING", such as count=count+1. Is it possible to declare global variable and then whenever i need , i can increment the value...in XSL ? or how to handle this case..in XSL ?

Could any one help..

Find the xml file as follows,

Envelope.xml
------------
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
  <Part File='Invoice.xml' LinkType='REL' Format='XML'/>
  <Part File='Inventory.xml' LinkType='REL' Format='XML'/>
</Envelope>



Invoice.xml
-----------
  <Invoice>
            <InvoiceItem CT="A" >
                        <Set>
                           <Att Ty="TM" Id="LC" />
                        </Set>
            </InvoiceItem>
            <InvoiceItem CT="A" >
                        <Set>
                           <Att Ty="TM" Id="LC" />
                        </Set>
            </InvoiceItem>
            <InvoiceItem CT="S" >
                        <Set>
                            <Att Ty="TM" Id="CC" />
                        </Set>
            </InvoiceItem>
  </Invoice>

Inventory.xml
-----------
  <Inventory>
            <Item>
        <Parts>
           <Att Id="myParts" />
        </Parts>
            </Item>
            <Item>
        <Parts>
           <Att Id="myParts" />
        </Parts>
            </Item>
  </Inventory>
Reply With Quote
  #2 (permalink)  
Old July 17th, 2008, 07:40 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't do it the way you are suggesting in XSLT, as variables cannot be updated. However you should be able to use the calculation which works out if it should display 'HEADER' to simply count the number of times that that would be displayed.

e.g.

in your template do something like this:

Code:
<xsl:if test="@Id='AB'">HEADER</xsl:if>
and then at the bottom:

Code:
There are <xsl:value-of select="count(//@Id='AB')"/> headers

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old July 18th, 2008, 03:17 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your right.

eg:
   In case if I want sum(HEADER+PRODUCT) such as

<xsl:if test="@Id='AB'">HEADER</xsl:if>
<xsl:if test="@Id='CD'">PRODUCT</xsl:if> , then

sum= ( <xsl:value-of select="count(//@Id='AB')"/> + <xsl:value-of select="count(//@Id='CD')"/> )

How to find SUM ?
Reply With Quote
  #4 (permalink)  
Old July 18th, 2008, 03:21 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:value-of select="count(//@Id='AB') + count(//@Id='CD')"/>

or

<xsl:value-of select="count(//@Id[.='AB' or .='CD'])"/>

or probably various other combinations of the above.


/- Sam Judson : Wrox Technical Editor -/
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
Count Sheikha ADO.NET 4 September 20th, 2010 03:47 AM
count lk79 XSLT 7 February 17th, 2008 03:07 PM
Setting xsl:variable maximum count isme XSLT 2 March 14th, 2006 03:39 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM



All times are GMT -4. The time now is 12:06 PM.


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