|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Consolidating xpath expressions... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|