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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.