473,800 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

search for maximum hierarchy

Dear All,

may be some of you can help me with an XSLT example how to solve the
following challange.
For the XML below I want to find out the maximum hierarchy level for a
specific element in my XSLT. The result for the example (searching for
<A/>) should be 4 as the element A is nested 4 times maximum.
I guess I have to use somehow the count function with 'following::A'
axes. But I could not get that to work yet.

Thanks a lot for your help
Rolf

<ROOT>
<A>
<A>
<B>
<C>
<A/> nested up to 3
</C>
</B>
</A>
<A>
<B>
<C>
<A>
<A/> nested up to 4
</A>
<C>
</B>
</A>
</A>
</ROOT>
Jul 20 '05
10 2109
J?rgen Kahrs <Ju************ *********@vr-web.de> wrote:
William Park wrote:
You had XSL and xmlgawk solution. Here is Bash shell solution:

start () { # Usage: start tag att=value ...
count=`echo ${XML_ELEMENT_S TACK[*]|/$1} | wc -w`
[[ count -gt $1 ]] && eval $1=`echo $count`
}
xml -s start "<ROOT>...</ROOT>"
declare -p A B C
Very short indeed. But a bit cryptic.
Explanation:
- ${...|/glob} returns all array element matching 'glob' pattern.
In this case, 'A', 'B', 'C'.


This is a very powerful feature that is missing in xmlgawk.
In xmlgawk an explicite loop is needed.


This is only available in my patch Bash shell. Standard Bash/Ksh/Zsh
doesn't have it. In Python, it's called list comprehension. But, in
shell-speak, it's nothing more than parameter expansion (around for 30
years) plus some content filtering (denoted by '|').
- `echo $count` is needed to strip leading whitespaces put there
by 'wc -w'.


The descendents of the Bourne shell are not really first choice
for arithmetic applications.


Actually, integer expression is fairly complete. For example,
${var[i]}
${var:i:j}
(( i ))
both 'i' and 'j' can be full arithmetic expression. It's the float
point which is the problem. Bash can't do floating point. Awk is much
better at that.

--
William Park <op**********@y ahoo.ca>
Open Geometry Consulting, Toronto, Canada
Jul 20 '05 #11

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

Similar topics

4
10536
by: JP SIngh | last post by:
Hi There I am creating a search page and need help writing the code to build the sql string. I have 3 fields on the main page which a user can choose to enter search terms in any of the 3 fields. My question is how do I write the logic so it only includes the fields in the search criteria where the user has entered anything.
11
4237
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will make the design looks a bit rediculous. He also said that the big text cannot be hidden. I am just trying to find a compromise. Here are the questions: (1) Is it true that a page with an <H1> tag and very big font size will make a search...
2
2477
by: Zambo via SQLMonster.com | last post by:
Hi! We have Sql Server 2000 in our server (NT 4). Our database have now about +350.000 rows with information of images. Table have lot of columns including information about image name, keywords, location, price, color mode etc. So our database don?t include the images itself, just a path to the location of every image. Keywords -field have data for example like this: cat,animal,pet,home,child with pet,child. Now our search use Full-Text...
83
5972
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd expect a much faster performance. I submitted my search over two minutes ago. I just finished this email to the list. The results have still not come back. I only searched for: SECURITY INVOKER
38
6944
by: Alan | last post by:
I want to change a 3 digits integer to characters, how can i do that? the 3 digits integer maybe 123, 23 or 3 I want to change the integer to "123", " 23" or " 3" thx
4
9021
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D
8
3476
by: ignatova | last post by:
Hello, I have been using IBM Net Search Extender to perform full text searches on text columns in relational tables in DB2 without any problems until now. However it doesn't seam to function properly for text indexes created on attributes of typed tables. Here are the issued commands: //create UDT db2 CREATE TYPE CompMetadata_T AS (dummy Integer,Text CLOB(100K),
5
8364
by: samoore33 | last post by:
I use the code below to return rows matching the state in the theState variable. I want to know if it is possible to search through the DataRow that I am returning with the search. I understand that that creates a DataRow Array. I searched through group postings and found where Cor had said something about bulding the DataTable back, not sure what that meant of if I could use it with this, but any help would be appreciated. Dim t As...
0
2464
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 good search engines are there like Google, Yahoo and Live to name few of them. Though this search engines have extremely efficient, complex and beautiful algorithms designed by gems of the industry, but still they may not deliver best results for...
0
9694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7584
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6824
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4152
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2953
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.