incrementing

D

David Schwartz

I need to create unique id's for DIVs for each instance of <foo>
within each instance of <bar> as follows. I iterate through both the
bars and foos via <apply-templates/>. I've tried to use position() but
that reflects the current <bar>, not the current <foo>.

========= sample xml ================
<!-- note the there may be other peer elements to the FOOs -->
<root>
<bar>
<foo>blah, blah, blah</foo>
<foo>bebop, smooth, cool, swing, super cool</foo>
</bar>
<bar>
<foo>baroque, classical, modern</foo>
<foo>chicago, delta</foo>
</bar>
</root>
==================================

========= sample html ================
page generated for the first <bar> instance:
<html>
<body>
<div id="foo1">blah, blah, blah</div>
<div id="foo2">bebop, smooth, cool, swing, super cool</div>
</body>
</html>

page generated for the second <bar> instance:
<html>
<body>
<div id="foo1">baroque, classical, modern</div>
<div id="foo2">chicago, delta</div>
</body>
</html>
=================================
 
R

Richard Tobin

I need to create unique id's for DIVs for each instance of <foo>
within each instance of <bar> as follows.

Use generate-id().

If you really need the position of <foo> within the whole document,
you could use count(preceding::foo), but it will be potentially
very slow.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top