473,405 Members | 2,373 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.

Search for

Hi,

I have a xml input file like this:

<root>
<element>
<name>elem1</name>
<child>
<name>1</name>
</child>
<child>
<name>2</name>
</child>
</element>
<element>
<name>elem2</name>
<child>
<name>2</name>
</child>
<child>
<name>3</name>
</child>
</element>

Now I want apply a template on every element element that has a child
with name="3" or name="1" for example.

I do this right now:
<xsl:for-each-group select="root/elment" group-by="name">
<xsl:if test="contains(current()/child/name, '3') or
contains(current()/child/name, '1')" >
<xsl:apply-templates select="current-group()"/>
</xsl:if>
</xsl:for-each-group>

But I get a "too many items" error. I guess because there are more
than one child nodes in a elment node.

Thanks
Peter
Feb 11 '08 #1
6 1566

ba*******@jubii.de <ba*******@jubii.dewrote in
<fe**********************************@q21g2000hsa. googlegroups.com>:
<root>
<element>
<name>elem1</name>
<child>
<name>1</name>
</child>
<child>
<name>2</name>
</child>
</element>
<element>
<name>elem2</name>
<child>
<name>2</name>
</child>
<child>
<name>3</name>
</child>
</element>
Not well-formed.
Now I want apply a template on every element element that
has a child with name="3" or name="1" for example.
<xsl:apply-templates
select="/root/element[child/name/text()='1' or
child/name/text()='3']"/>
<xsl:for-each-group select="root/elment" group-by="name">
<xsl:if test="contains(current()/child/name, '3') or
contains(current()/child/name, '1')" >
<xsl:apply-templates select="current-group()"/>
</xsl:if>
</xsl:for-each-group>
I think I'll just add xsl:for-each-group to my list of Evil
Stuff That Confuses Neophytes.

--
When all you have is a transformation engine, everything
looks like a tree.
Feb 11 '08 #2
ba*******@jubii.de wrote:
Now I want apply a template on every element element that has a child
with name="3" or name="1"
<xsl:apply-templates select="/root/element[child/name=3 or child/name=1]"/>

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 11 '08 #3
Well this works, but not like I need it.
I should have mentioned what I do in my template that I apply.

I want to output the element names but only once the same.
With the current solution I get the element names many times, to be
exactly once for every child that's name is 1 or 3.

That is why i grouped the names in a for-each-group loop.

On 11 Feb., 16:22, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
barkee...@jubii.de wrote:
Now I want apply a template on every element element that has a child
with name="3" or name="1"

<xsl:apply-templates select="/root/element[child/name=3 or child/name=1]"/>

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 11 '08 #4
ba*******@jubii.de wrote:
I want to output the element names but only once the same.
See the XSLT FAQ website's "grouping" page; that should give you some
useful techniques.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 11 '08 #5
ba*******@jubii.de wrote:
Well this works, but not like I need it.
I should have mentioned what I do in my template that I apply.

I want to output the element names but only once the same.
With the current solution I get the element names many times, to be
exactly once for every child that's name is 1 or 3.

That is why i grouped the names in a for-each-group loop.
I think it is better you provide a sample of your XML that makes it
clear what you need to group on and then describe the result you want to
create with your stylesheet.
So far we can only guess what you want, here is my attempt at guessing

<xsl:for-each-group select="root/element[child/name = '1' or
child/name = '3']" group-by="name">
<xsl:value-of select="current-grouping-key()"/>
<xsl:if test="position() != last()">
<xsl:text</xsl:text>
</xsl:if>
</xsl:for-each-group>

It outputs the grouping key of each group.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 11 '08 #6
Hi folks,

that was the clue:
<xsl:for-each-group select="root/element[child/name = '1' ....

Now it works.
Thanks very much!

I really have my problems with this xslt stuff :-)

Bye Peter

On 11 Feb., 17:48, Martin Honnen <mahotr...@yahoo.dewrote:
barkee...@jubii.de wrote:
Well this works, but not like I need it.
I should have mentioned what I do in my template that I apply.
I want to output the element names but only once the same.
With the current solution I get the element names many times, to be
exactly once for every child that's name is 1 or 3.
That is why i grouped the names in a for-each-group loop.

I think it is better you provide a sample of your XML that makes it
clear what you need to group on and then describe the result you want to
create with your stylesheet.
So far we can only guess what you want, here is my attempt at guessing

<xsl:for-each-group select="root/element[child/name = '1' or
child/name = '3']" group-by="name">
<xsl:value-of select="current-grouping-key()"/>
<xsl:if test="position() != last()">
<xsl:text</xsl:text>
</xsl:if>
</xsl:for-each-group>

It outputs the grouping key of each group.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Feb 11 '08 #7

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

Similar topics

0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
39
by: Noticedtrends | last post by:
Can inference search-engines narrow-down the number of often irrelevant results, by using specific keywords; for the purpose of discerning emerging social & business trends? For example, if...
22
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
by: passion | last post by:
"Specialized Search Engines" along with Google Search Capability (2 in 1): http://specialized-search-engines.blogspot.com/ Billions of websites are available on the web and plenty of extremely...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.