473,803 Members | 4,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

numbering across different elements

hi,
suppose i have:

<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
</a>

and i want to extract the elements where i="Y" such that i get something like
<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
</x>

how would i get the numbering to work across the different elements?

thanks,
mike
Jul 20 '05 #1
10 1797
In article <72************ **************@ posting.google. com>,
Mike Dickens <mi**@progres s-partnership.co. uk> wrote:
and i want to extract the elements where i="Y" such that i get something like
<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
</x>

how would i get the numbering to work across the different elements?


Use xsl:number with the "count" attribute to specify which elements
are counted.

-- Richard
Jul 20 '05 #2
On 27 Oct 2004 09:06:13 -0700, mi**@progress-partnership.co. uk (Mike Dickens)
wrote:
hi,
suppose i have:

<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
</a>

and i want to extract the elements where i="Y" such that i get something like
<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
</x>

how would i get the numbering to work across the different elements?

thanks,
mike

mmmm.. you just want to enumerate all of your elements?
What technology is at your disposal?
In XQuery, using books.xml,
this query:

for $t at $i in document("books .xml")//*[@year="1994"]
return <Response>{$i , name($t), string($t/@year)}</Response>

returns this data:

<Response>1 book 1994</Response>
Here is books.xml (from katz_c01.pdf tutorial I found via google at
http://www.datadirect.com/news/whats...book/index.ssp)
<bib>
<book year="1994">a19 94 <title>TCP/IP Illustrated</title>
<author>
<last>Stevens </last>
<first>W.</first>
</author>
<publisher>Addi son-Wesley</publisher>
<price>65.95</price>
</book>
<book year="1992">a19 92<title>Advanc ed Programming in the UNIX
Environment</title>
<author>
<last>Stevens </last>
<first>W.</first>
</author>
<publisher>Addi son-Wesley</publisher>
<price>65.95</price>
</book>
<book year="2000">a20 00<title>Data on the Web</title>
<author>
<last>Abiteboul </last>
<first>Serge</first>
</author>
<author>
<last>Buneman </last>
<first>Peter</first>
</author>
<author>
<last>Suciu</last>
<first>Dan</first>
</author>
<publisher>Morg an Kaufmann Publishers</publisher>
<price>65.95</price>
</book>
<book year="1999">a19 99<title>The Economics of Technology and Content
for Digital TV</title>
<editor>
<last>Gerbarg </last>
<first>Darcy</first>
<affiliation>CI TI</affiliation>
</editor>
<publisher>Kluw er Academic Publishers</publisher>
<price>129.95 </price>
</book>
</bib>
Jeff Kish
Jul 20 '05 #3
Mike Dickens wrote:
<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
</a>

and i want to extract the elements where i="Y" such that i get something like
For the sake of comparison, here is a solution in XMLgawk:
BEGIN {
XMLMODE=1
print "<x>"
}

XMLSTARTELEM {
if (XMLATTR["i"] == "Y")
print " <y>" ++n ". " XMLATTR["j"] "</y>"
}

END { print "</x>" }

I tested it and it produced:

<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. ffff</y>
</x>
how would i get the numbering to work across the different elements?


You probably mean how to make sure that nodes
at all nesting levels are treated in the same
way. In XMLgawk this is no problem because the
interpreter traverses all nodes anyway.
Jul 20 '05 #4
whoops,
i forgot to mention. i need to do this as an xsl transform. i am
thinking <xsl:number> is probably the way i want to go, but am unsure
as to how to go about it. all the examples i can find refer to
elements of the same type, not amalgamating different types as i want
to do here.

mike.
mi**@progress-partnership.co. uk (Mike Dickens) wrote in message news:<72******* *************** ****@posting.go ogle.com>...
hi,
suppose i have:

<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
</a>

and i want to extract the elements where i="Y" such that i get something like
<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
</x>

how would i get the numbering to work across the different elements?

thanks,
mike

Jul 20 '05 #5
Mike Dickens wrote:
<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
Notice this one ^^^^
</a>

and i want to extract the elements where i="Y" such that i get something like
<x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
I think you have an error in 3.
</x>


The script that I posted yesterday found this error.
Jul 20 '05 #6
Hi Mike,

Try something like...

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>

<xsl:template match="/a">
<xsl:copy>
<xsl:apply-templates select="*[@i = 'Y']"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<y>
<xsl:value-of select="positio n()"/>
<xsl:text>. </xsl:text>
<xsl:value-of select="@j"/>
</y>
</xsl:template>
</xsl:stylesheet>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Mike Dickens" <mi**@progres s-partnership.co. uk> wrote in message
news:72******** *************** ***@posting.goo gle.com...
whoops,
i forgot to mention. i need to do this as an xsl transform. i am
thinking <xsl:number> is probably the way i want to go, but am unsure
as to how to go about it. all the examples i can find refer to
elements of the same type, not amalgamating different types as i want
to do here.

mike.
mi**@progress-partnership.co. uk (Mike Dickens) wrote in message

news:<72******* *************** ****@posting.go ogle.com>...
hi,
suppose i have:

<a>
<b i="Y" j="aaaa"/>
<c i="N" j="bbbb"/>
<d i="Y" j="cccc"/>
<e i="N" j="dddd"/>
<f i="N" j="eeee"/>
<g i="Y" j="ffff"/>
</a>

and i want to extract the elements where i="Y" such that i get something like <x>
<y>1. aaaa</y>
<y>2. cccc</y>
<y>3. gggg</y>
</x>

how would i get the numbering to work across the different elements?

thanks,
mike

Jul 20 '05 #7
In article <72************ **************@ posting.google. com>,
Mike Dickens <mi**@progres s-partnership.co. uk> wrote:
i forgot to mention. i need to do this as an xsl transform. i am
thinking <xsl:number> is probably the way i want to go, but am unsure
as to how to go about it.


The count attribute is a pattern which matches the elements that
should be counted. So you just need something like:

<xsl:template match="*[@i = 'Y']">
<y>
<xsl:number count="*[@i = 'Y']"/>
<xsl:text>. </xsl:text>
<xsl:value-of select="@j"/>
</y>
</xsl:template>

-- Richard
Jul 20 '05 #8
i think i simplified my example to much. a more accurate file would
be:
<a>
<b a="Y" m="aaaa"/>
<c b="N" n="bbbb"/>
<d c="Y" o="cccc"/>
<e d="N" p="dddd"/>
<f e="N" q="eeee"/>
<g f="Y" r="ffff"/>

this means the is no commonality in the source elements i'm massaging
into a numbered list in the result elements.

in the end i just persuaded the powers that be to do it differently :)

thanks for the help tho'
mike.
ri*****@cogsci. ed.ac.uk (Richard Tobin) wrote in message news:<cl******* ****@pc-news.cogsci.ed. ac.uk>...
In article <72************ **************@ posting.google. com>,
Mike Dickens <mi**@progres s-partnership.co. uk> wrote:
i forgot to mention. i need to do this as an xsl transform. i am
thinking <xsl:number> is probably the way i want to go, but am unsure
as to how to go about it.


The count attribute is a pattern which matches the elements that
should be counted. So you just need something like:

<xsl:template match="*[@i = 'Y']">
<y>
<xsl:number count="*[@i = 'Y']"/>
<xsl:text>. </xsl:text>
<xsl:value-of select="@j"/>
</y>
</xsl:template>

-- Richard

Jul 20 '05 #9
In article <72************ **************@ posting.google. com>,
Mike Dickens <mi**@progres s-partnership.co. uk> wrote:
i think i simplified my example to much. a more accurate file would
be:


There is no problem with this. So long as the pattern
in the count attribute of the sort matches the same nodes as
the match attribute of the template, it will count those elements.

If you are listing elements that have any attribute equal to Y, just
use @*='Y' instead of @i='Y'.

-- Richard
Jul 20 '05 #10

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

Similar topics

2
4026
by: Andy Glew | last post by:
I have long looked for (and occasionally posted questions to groups such as this about) a tool that can take a group of HTML pages (nowadays XHTML, or XML) and produce a nicely formatted printable documented, featuring. * pagination * section numbering * including Dewey decimal section numbering such as Section 1.2.3 for H3
2
1621
by: Dwayne Wilkinson | last post by:
Hi, I need to number a set of PARA nodes as outlined below: <?xml version="1.0" encoding="utf-8"?> <DESCRIPT> <PARA0> <PARA>Paragraph 1</PARA> </PARA0> <PARA0>
2
2086
by: Mike Dickens | last post by:
hi, i have a query regarding numbering one set of elements as filtered by another set. eg if i have <?xml version="1.0" encoding="ISO-8859-1"?> <a> <b i="1" j="aaaa"/> <b i="2" j="bbbb"/> <b i="3" j="aaaa"/> <c i="1" j="xxxx"/>
6
2857
by: Stanimir Stamenkov | last post by:
So if the 'type' attribute of the OL element is deprecated and authors should rely only on stylesheets how one could use a reference (as clear text) in the content to a particular list element? Suppose I have: <ol type="1" id="main"> <li>baba</li> <li>lele <ol type="a" id="ext">
6
7397
by: Christian Roth | last post by:
Hello, how do I offset the numbering of a list in XHTML Strict (+CSS) in current browsers? What I want is something like: 5. Item a 6. Item b 7. Item c
2
2310
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a simple "numbering records on a report" question. It is more complex than that. I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. ...
9
5319
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of copy paste (I hear this will improve in ASP.Net 2 via master pages). When I navigate from one page to the next the header and footer user controls lose their state because they are effectively different instances of the user control. Is there...
15
3004
by: bg_ie | last post by:
Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code -
1
1933
by: Datawich | last post by:
Hi. By persistence, I've discovered that when several nested elements in a schema are each qualified by a namespace, I can successfully reference them in a select statement by qualifying each element by its namespace in succession. For example, for a schema that qualfies each element in a nested series "command, heading, pivot table" by "xs", I can use an xpath statement like "//xs:command/xs:heading/ xs:pivotTable" to select the pivot...
0
9699
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
10309
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
10289
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9119
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
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
5496
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.