473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Parsing and counting using XSLT

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 "count" attribute. The new "count" attribute provides the number of occurrences of that value .Must parse and input element on semi-colon if this delimits a list of values.

input XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<School>
<student rec='1'>
<name>Robart J</name>
</student>
<student rec='2'>
<name>Alex M; Peter R</name>
</student>
<student rec='3'>
<name>Alex M;Robart J; Dave T</name>
</student>
</School>


Output XML should be like..

<School>
<name count='2'>Robart J</name>
<name count='2'>Alex M</name>
<name count='1'>Peter R</name>
<name count='1'>Dave T</name>
</School>


I am using XSLT 2.0 processor. I just can't work it out. Is this even possible with XSL? Or is there a
better way of doing the substitution that I'm missing? Please let me know if it is possible in XSLT 1.0 ….

Thanks in advance

Manish
Jan 23 '08 #1
2 1650
jkmyoung
2,057 Expert 2GB
Reposted for the benefit of this forum.

I would suggest creating a temporary variable result for each name, with each name parsed out. eg temporary result would be:
<name>Robart J</name>
<name>Alex M</name>
<name>Peter R</name>
<name>Alex M</name>
<name>Robart J</name>
<name>Dave T</name>

Then use the count() function to do the rest.
It would be easier in XSLT 2.0 if you use this method. In 1.0 you'd have to use node-set extension functions.
Jan 23 '08 #2
Thanks guys for your valuable suggestions.

By the way I got the solution. Following XSLT 2.0 code is working to get the required output..

<xsl:for-each-group select="School/student" group-by="name/tokenize(., ';\s*')">
<xsl:sort select="current-grouping-key()"/>
<name count="{count(current-group())}">
<xsl:value-of select="current-grouping-key()"/>
</name>
</xsl:for-each-group>

Thanks again,
Manish
Jan 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dev | last post by:
Hey all, i am a newbie with xsl&xml parsing i have a xml doc and i try to make axsl and parse it to webbrowser.. how must i do that? in php just include xml file or must i parse it to a...
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>....
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
6
by: David Walker | last post by:
Hi, I have an XML file created by a third party in which an element with a simple content model has a text value consisting of 2 parts separated by a colon, like this ...
35
by: .:mmac:. | last post by:
I have a bunch of files (Playlist files for media player) and I am trying to create an automatically generated web page that includes the last 20 or 30 of these files. The files are created every...
2
by: Benzari.Alex | last post by:
Hello, the majority of my sites use PHP MYSQL and XSLT for dynamic pages and all of it works ok for English characters. The problem begins when I try to use Romanian or Russian characters while...
2
by: veracon | last post by:
Hello, I'm looking to use XML and XSLT for templates in a system I'm writing, however I'm not really sure which parser is the "best". Basically, which library has the most features, and which is...
1
by: qbp90x5lb | last post by:
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I...
2
by: doby48 | last post by:
I have an html document and an XSLT currently. The XML that I need to parse is on a different remote server. Now, the XSLT works without issue as does the HTML document with XMLDOM if the XML file is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.