Subject: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.
Subject: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']