473,471 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

xslt counting

hi,

i'm trying to count something in xml via xsl and don't quite get it. i
have something like (don't mind it's not logical)

<doc>
<s>
<w type="a">how</w>
<w type="b">are</w>
<w type="a">you</w>
</s>
<s>
<w type="c">i</w>
<w type="a">am</w>
<w type="b">fine</w>
</s>
<s>
<w type="a">i</w>
<w type="a">am</w>
<w type="b">fine</w>
</s>
<s>
<w type="a">i</w>
<w type="a">am</w>
<w type="b">fine</w>
</s>
</doc>

i'm counting all <s>-elements with a <w type="a">-element as first
element by doing:

<xsl:value-of select="count(//s/w[position()=1 and contains(@type,'a')])"/>

(results in "3" for the above example; i need to use "contains" since it
can also look like type="a ff ee")

but i'm stuck finding a proper query for (all <s> elements having a <w
type="a"> element as first element and a <w type="b"> element as second)
(should result in "1" for the above example) and for (all <s> elements
having a <w type="a"> element as first element and a <w type="b">
element as greater-than-second) (would resoult in "2" in the above example)

Any help?

Thanks,

Herr Herrner
Jul 20 '05 #1
4 1352
Tempore 15:23:43, die Wednesday 09 March 2005 AD, hinc in foro {comp.text.xml} scripsit Herr Herrner <ne************@spamgourmet.com>:
i'm counting all <s>-elements with a <w type="a">-element as first
element
Hi,
<xsl:value-of select="count(//s/w[position()=1 and contains(@type,'a')])"/>

(results in "3" for the above example; i need to use "contains" since it
can also look like type="a ff ee") The abbreviated syntax would be:
<xsl:value-of select="count(//s[w[1][contains(@type,'a')]])"/>
but i'm stuck finding a proper query for (all <s> elements having a <w
type="a"> element as first element and a <w type="b"> element as second) <xsl:value-of select="count(//s[w[1][contains(@type,'a')] and w[2][contains(@type,'b')]])"/>
(should result in "1" for the above example) and for (all <s> elements
having a <w type="a"> element as first element and a <w type="b">
element as greater-than-second) (would resoult in "2" in the above example)


<xsl:value-of select="count(//s[w[1][contains(@type,'a')] and count(w[2] | w[contains(@type,'b')][1]) = 2 ])"/>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Fiat W3C in tenebris
Jul 20 '05 #2
Thanks a lot! That did the trick. My second "wish" was simply
accomplished by:

<xsl:value-of select="count(//s[w[1][contains(@type,'a')] and
w[position()>2][contains(@type,'b')]])"/>

so what does your last example do?!

Thanks again,

Herr Herrner
Joris Gillis wrote:
Tempore 15:23:43, die Wednesday 09 March 2005 AD, hinc in foro
{comp.text.xml} scripsit Herr Herrner <ne************@spamgourmet.com>:
i'm counting all <s>-elements with a <w type="a">-element as first
element

Hi,
<xsl:value-of select="count(//s/w[position()=1 and
contains(@type,'a')])"/>

(results in "3" for the above example; i need to use "contains" since it
can also look like type="a ff ee")


The abbreviated syntax would be:
<xsl:value-of select="count(//s[w[1][contains(@type,'a')]])"/>
but i'm stuck finding a proper query for (all <s> elements having a <w
type="a"> element as first element and a <w type="b"> element as second)


<xsl:value-of select="count(//s[w[1][contains(@type,'a')] and
w[2][contains(@type,'b')]])"/>
(should result in "1" for the above example) and for (all <s> elements
having a <w type="a"> element as first element and a <w type="b">
element as greater-than-second) (would resoult in "2" in the above
example)

<xsl:value-of select="count(//s[w[1][contains(@type,'a')] and count(w[2]
| w[contains(@type,'b')][1]) = 2 ])"/>
regards,

Jul 20 '05 #3
Tempore 16:12:31, die Wednesday 09 March 2005 AD, hinc in foro {comp.text.xml} scripsit Herr Herrner <ne************@spamgourmet.com>:
<xsl:value-of select="count(//s[w[1][contains(@type,'a')] and
w[position()>2][contains(@type,'b')]])"/>

so what does your last example do?!

The difference is that my last example would NOT count:

<s>
<w type="a">how</w>
<w type="b">are</w>
<w type="b">you</w>
</s>

while your XPath would include it in counting.

I could not figure out what the wished behaviour was, so which is it?

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Fiat W3C in tenebris
Jul 20 '05 #4
> I could not figure out what the wished behaviour was, so which is it?
I can't say really, since something like

<s>
<w type="a">how</w>
<w type="b">are</w>
<w type="b">you</w>
</s>

won't happen in the "real thing", but if it was to happen, your example
would be the better one. Thanks again,

Herr Herrner
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
9
by: Martin Plantec | last post by:
Hello, I have managed (with your help!) to make a working XSLT stylesheet; it works fine locally (Windows Apache + PHP with Sablotron 1.0), but it fails on the remote host (FreeBSD Apache + PHP...
4
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is...
12
by: Jeff Calico | last post by:
I have 2 XML data files that I want to extract data from simultaneously and transform with XSLT to generate a report. The first file is huge and when XSLT builds the DOM tree in memory, it runs...
2
by: manishj | last post by:
Hello! I m trying to transform a XML file into new XML file . Description: Each unique value from the <name> elements in the input record are to be uniqued, alphabetized and stored with a...
4
by: saritha2008 | last post by:
Hi, Iam working on converting one of xml file to other form of xml using XSLT. As part of this, I need to count the no. of "component" nodes in the xml file given below. If there is only one...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.