473,405 Members | 2,344 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,405 software developers and data experts.

grouping elements

Hi,
I have the following xml file which I would like to transform to
another structure:

<person>
<dept>
<gr_name>sale</gr_name>
<gr_id>2<gr_id>
....
<dept>
<name>Peter Pan</name>
<dept>
</person>

<person>
<dept>
<gr_name>production</gr_name>
<gr_id>3<gr_id>
....
<dept>
<name>John John</name>
<dept>
</person>

<person>
<dept>
<gr_name>package</gr_name>
<gr_id>11<gr_id>
....
<dept>
<name>Roy Kemp</name>
<dept>
</person>
......

New xml would look like this:
<sale>Peter Pan</sale>
<production_package_etc>John John<production_package_etc>
<production_package_etc>Roy Kemp<production_package_etc>

I have written some thing like this and it is not working. What is
wrong her?
<xsl:for-each select="//person">
<xsl:if test="//person/dept/gr_id = 1">
<sale<xsl:value-of select="name" /><sale>
</xsl:if>
</xsl:for-each>

<xsl:for-each select="//person">
<xsl:if test="//person/dept/gr_id != 1">
< production_package_etc<xsl:value-of select="name" /
>< production_package_etc>
</xsl:if>
</xsl:for-each>

Thanks in advance.
Jun 27 '08 #1
1 1199
of*****@yahoo.no wrote:
I have the following xml file which I would like to transform to
another structure:

<person>
<dept>
^^^^^^
So here is a 'dept' start tag
<gr_name>sale</gr_name>
<gr_id>2<gr_id>
....
<dept>
^^^^^^
And here is another one
<name>Peter Pan</name>
<dept>
^^^^^^
And here is yet another one while there are no matching end tags.
Can you post a well-formed sample? Currently it is not clear how your
input XML looks.

<xsl:for-each select="//person">
<xsl:if test="//person/dept/gr_id = 1">
You need a relative XPath here e.g.
<xsl:if test="dept/gr_id = 1">
but it is even better to write templates e.g.
<xsl:template match="person[dept/gr_id = 1]">
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

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

Similar topics

5
by: Mike King | last post by:
I don't know how to group the following data in the way I want it. I want the output of the transformation to be "5678". Does anyone know what I am doing worry? <?xml version="1.0"?> <data>...
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...
0
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...
2
by: Chris Beach | last post by:
Hi there. I'd like to be able to group together inputs on an HTML form inside, say, a <div> or <fieldset> and then use javascript to iterate through the controls in the group and disable them....
3
by: _DD | last post by:
I believe Balena's Best Practices book suggests grouping quite a few classes into each namespace. I don't remember a number, but this has me curious about how other programmers handle this. If...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.