XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2003, 11:11 AM
ojl96 ojl96 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Manchester:UK
Posts: 1 ojl96 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Consolidating xpath expressions...

Hi guys!

Can someone give me some advice as to how I can change these three lines of code into a single line??

<xsl:for-each select="//client[not($clientid) or @ID=$clientid]">
<xsl:for-each select="descendant-or-self::client">
<xsl:for-each select="usage[@TOTALSENT > 0]">
..... do something here....
<xsl:for-each>
<xsl:for-each>
<xsl:for-each>


It would be really great if I could just do.....
<xsl:for-each select="super select that does all that!">
..... do something here....
</xsl:for-each>



The transformation is on an xml document that's a little bit like this...


<client ID=1>
<client ID=2>
<client ID=3>
<usage @TOTALSENT=5/>
</client>
<client>
<usage @TOTALSENT=9/>
<client ID=4>
</client>
</client>


Any help would be great!
Thanks!

Reply With Quote
  #2  
Old December 4th, 2003, 10:02 AM
timothtimoth timothtimoth is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 timothtimoth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Maybe I'm missing some thing

but to write that on a single line should be

<xsl:for-each select="//client[not($clientid) or @ID=$clientid]/descendant-or-self::client/usage[@TOTALSENT > 0]">


But there are a number of ways you might be able to optimize that statement.

1) //client[not($clientid) or @ID=$clientid]/descendant::usage[@TOTALSENT > 0]"

if you want all usage elements with a totalset greater than 0 that have ancestor elements that have ids equal to the client id

2) descendant::client[@ID=$client]/descendant::usage[@TOTALSENT > 0]

If you just want all usage elements that are descendants of the current context
3) descendant::usage

Of course you get the same results with all of these statements with the xml you provided. However if the xml document varies at all ( and I suspect it does quite a bit) then thses statements might be a little to broad for you purposes.

Axes are powerful and tend to pull a lot of nodes. Controlling the selection is often difficult.

You could probably accomplish what you are trying to do much more easily through keys.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Consolidating xpath expressions...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT