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 July 17th, 2008, 07:32 AM
Authorized User
 
Join Date: Jul 2008
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>
 
Old July 17th, 2008, 07:40 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 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 -/
 
Old July 18th, 2008, 03:17 AM
Authorized User
 
Join Date: Jul 2008
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 ?
 
Old July 18th, 2008, 03:21 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/





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





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