473,224 Members | 1,395 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,224 software developers and data experts.

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 1762
In article <72**************************@posting.google.com >,
Mike Dickens <mi**@progress-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">a1994 <title>TCP/IP Illustrated</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="1992">a1992<title>Advanced Programming in the UNIX
Environment</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="2000">a2000<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>Morgan Kaufmann Publishers</publisher>
<price>65.95</price>
</book>
<book year="1999">a1999<title>The Economics of Technology and Content
for Digital TV</title>
<editor>
<last>Gerbarg</last>
<first>Darcy</first>
<affiliation>CITI</affiliation>
</editor>
<publisher>Kluwer 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.google. 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:stylesheet 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="position()"/>
<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**@progress-partnership.co.uk> wrote in message
news:72**************************@posting.google.c om...
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.google. 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**@progress-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**@progress-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**@progress-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
Mike Dickens <mi**@progress-partnership.co.uk> 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?


If you can compile a Bash shell, then

start () {
local "$@" # b i=Y j=aaaa
[ "$i" = Y ] && echo $((++count)). $j
}
xml -s start "`< file.xml`"

will print

1. aaaa
2. cccc
3. ffff

Ref:
http://freshmeat.net/projects/bashdiff/

--
William Park <op**********@yahoo.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

2
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...
2
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
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...
6
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? ...
6
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
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...
9
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...
15
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
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.