Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 15th, 2006, 07:35 PM
C Wilson
Guest
 
Posts: n/a
Default select items based on attribute value in a second, same-levelcollection

I may need to resort to some other tool but right now I'm limiting
myself to XPath and XSLT and suchlike. I'm an XPath newbie.
I'm framing my question as a structural one and what I think I'm
looking for is a structural answer, not exact source code.
I have a document that has several collections at the same level. The
two that concern me are entities and numeric snapshots. That is, the
document contains a set of entities, each of which has, say, an ID
and a color. At the same level there is a collection of clumps of
numeric values, a snapshot of the state of the entity; each clump has
the ID of the entity of which it is a snapshot. Let's say weight and
ring size.
<blather>
<entities>
<entity id="x" color="magenta">
</entity>
</entities>
<snapshots>
<snapshot eid="x">
<weight>23</weight>
</snapshot>
</snapshots>
<blather>
I have worked up an XSLT that computes the grand total of all the
weights. I can do this looking only at the collection of snapshots.
Now I need to exclude some snapshots based on the color of their
associated entities. My goal is to calculate the grand total of all
weights for entities that (say) are not blue.
I'm open to such ideas as preprocessing the document to add the color
as an attribute of the snapshot, or whatever goes with the grain of
this XML world.
chw
  #2  
Old December 16th, 2006, 01:55 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: select items based on attribute value in a second, same-levelcollection

C Wilson wrote:
Quote:
I may need to resort to some other tool but right now I'm limiting
myself to XPath and XSLT and suchlike. I'm an XPath newbie.
I'm framing my question as a structural one and what I think I'm
looking for is a structural answer, not exact source code.
I have a document that has several collections at the same level. The
two that concern me are entities and numeric snapshots. That is, the
document contains a set of entities, each of which has, say, an ID
and a color. At the same level there is a collection of clumps of
numeric values, a snapshot of the state of the entity; each clump has
the ID of the entity of which it is a snapshot. Let's say weight and
ring size.
<blather>
<entities>
<entity id="x" color="magenta">
</entity>
</entities>
<snapshots>
<snapshot eid="x">
<weight>23</weight>
</snapshot>
</snapshots>
<blather>
I have worked up an XSLT that computes the grand total of all the
weights. I can do this looking only at the collection of snapshots.
Now I need to exclude some snapshots based on the color of their
associated entities. My goal is to calculate the grand total of all
weights for entities that (say) are not blue.
I'm open to such ideas as preprocessing the document to add the color
as an attribute of the snapshot, or whatever goes with the grain of
this XML world.
chw
index your entities

<xsl:key name="e" match="entity" use="@id"/>

then

My goal is to calculate the grand total of all
Quote:
weights for entities that (say) are not blue.
is

sum(snapshot[not(key('e',@eid)/@color='blue')]/weight)

If you have a DTD and @id is of type ID then you don't need xsl:key and
can instead do

sum(snapshot[not(id(@eid)/@color='blue')]/weight)

but key() is a bit safer avoids questions about whether the xml parser
being used does or does not read the DTD.

David
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles