XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Elke FriedleinSubject: XSL: Counting items / remembering the right value
Author: Elke Friedlein
Date: 24 Nov 2005 11:18 AM
I have a XML-File which I want to transform to another XML with help of XSL.
The Source-XML contains various attributes, in which I’m interested (e.g. 7), in mixed order and many of them.
f.eg.
<root>
<file>
<error source=”X”/>
<error source=”J”/>
<error source=”X”/>
</file>
<file>
<error source=”Z”/>
</file>
<file>
<error source=”Z”/>
<error source=”J”/>
<error source=”X”/>
<error source=”Z”/>
<error source=”Z”/>
</file>
</root>

In XSL I want to count how often theses attributes are in the Source XML
Output may be like this:
<figures>
<figure>
<name>Java</name>
<value>2</value> //2x ‘J’ in source-XML
</figure>
<figure>
<name>Zero</name>
<value>4</value> //4x ‘Z’ in source-XML
</figure>
<figure>
<name>Xalan</name>
<value>3</value> // 3x ‘X’ in source-XML
</figure>
</figures>

To figure out the different cases I use a for-each in combination with choose and when, this is works fine.
My Problem is how can I count the items in my case / how can I make a variable/param that saves my current value correctly.

<xsl:for-each select="root/file/error ">
<xsl:choose>
<xsl:when test="contains(@source,'J')">
//Counting????!!!???
</xsl:when>
…..
</xsl:choose>
</xsl:for-each>
<figures>
<figure>
<name>Java</name>
<value>????</value>
</figure>

</figures>

Hope my question is clear.
Thank you for helping me

Postnext
hardik mehtaSubject: XSL: Counting items / remembering the right value
Author: hardik mehta
Date: 24 Nov 2005 11:41 AM
Hi Elke,

I am also new to xslt but I think this type of counting i.e. incrementing the variable is not posible in xslt.

what u can do is

<xsl:variable name="count" select="count(root/file/error[@source = 'testval'] />

this will store the count in count variable...

Hardik





Postnext
Elke FriedleinSubject: XSL: Counting items / remembering the right value
Author: Elke Friedlein
Date: 24 Nov 2005 12:15 PM
Hi Hardik,
thanks for your advise,it's a real good idea. But do you know if I can add or-Conditions?
like this:

<xsl:variable name="count" select="count(root/file/error[@source = 'testval'|| @source = 'testval2'] />

or is it probably better to sum my count-Variables at the end.

Elke

Postnext
hardik mehtaSubject: XSL: Counting items / remembering the right value
Author: hardik mehta
Date: 24 Nov 2005 12:22 PM
hi Elke,

i think we can add the conditions in the predicate (the square bracket is known as predicate) but I recently had some problems when i was using and conditions with node list..anyway it may work for you..

you can use and and or

as..

select="root/node/[@attrib1 = 't1' and @attrib2 ='t2']

Hardik

Posttop
hardik mehtaSubject: XSL: Counting items / remembering the right value
Author: hardik mehta
Date: 25 Nov 2005 04:04 AM
Elke,

I am sorry but there is a typo in my last reply..


<xsl:variable name="count" select="count(root/file/error[@source = 'testval' and @otherattrib = 'testval2'] />

so the slash after node should not be there...


Hardik

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.