Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XPath: Using the outside context inside a square bracket predicate (http://www.velocityreviews.com/forums/t587223-xpath-using-the-outside-context-inside-a-square-bracket-predicate.html)

Wabiloo 01-25-2008 04:17 PM

XPath: Using the outside context inside a square bracket predicate
 
Hi,

Although I've been using XPath for a long time, I'm stuck on what
seems to be a simple problem.

In the following document, I want to count the number of times a set
of nodes (identified through an attribute) is reused in the rest of
the document.

<PlayerConfiguration>
<Type name='Portrait'>
<Description>Portrait screens in PIPs</Description>
<PublicVariables>
<Var name='_ContentDiagnostics'>Off</Var>
<Var name='Show_TOC_ES'>0</Var>
<Var name='Show_TOC_EM'>0</Var>
<Var name='Show_TOC_FC'>0</Var>
<Var name='Show_TOC_SE'>0</Var>
</PublicVariables>
</Type>

<Player id='TEST-P' ip='192.168.86.60' type='Portrait'>
<PublicVariables>
<Var name='Show_TOC_ES'>1</Var>
<Var name='Show_TOC_EM'>1</Var>
<Var name='Show_TOC_FC'>1</Var>
<Var name='Show_TOC_SE'>1</Var>
</PublicVariables>
</Player>
<Player id='PIP1-P' ip='' type='Portrait'>
<PublicVariables>
<Var name='Show_Area_ARCD'>1</Var>
<Var name='Show_TravelInfo_Train'>1</Var>
<Var name='Show_Weather_National'>1</Var>
<Var name='Show_TravelInfo_NRE'>1</Var>
</PublicVariables>
</Player>
<Player id='PIP2a-P' ip='' ignore='0' type='Portrait'>
<PublicVariables>
<Var name='Show_Area_ARCD'>1</Var>
<Var name='Show_TOC_ES'>1</Var>
</PublicVariables>
</Player>
</PlayerConfiguration>

The following XPath is incorrect, as the ./@name is evaluated within
the context of the square bracket, and not in the outside context

//Type[1]/PublicVariables/Var/count(//Player/PublicVariables/
Var[@name=./@name])

The following XPath is also incorrect, as it is only valid in the
context of XSL (which is not the case for me):

//Type[1]/PublicVariables/Var/count(//Player/PublicVariables/
Var[@name=current()/@name])

Is there a way of getting this with a single XPath expression without
using XSL?

The output I'd expect is for each of the variables in the Type node at
the top (there's 4 of them), how many times they appear in the Player
nodes below (eg. 'Show_TOC_ES' appears twice).

Help much appreciated!

Martin Honnen 01-25-2008 04:38 PM

Re: XPath: Using the outside context inside a square bracket predicate
 
Wabiloo wrote:

> //Type[1]/PublicVariables/Var/count(//Player/PublicVariables/
> Var[@name=current()/@name])
>
> Is there a way of getting this with a single XPath expression without
> using XSL?


You seem to want to use XPath 2.0, right?
In that case
for $v in //Type[1]/PublicVariables/Var
return count(//Player/PublicVariables/Var[@name = $v/@name]
should do.

If you want to use XPath 1.0 then I don't understand the XPath
expressions you have posted.

--

Martin Honnen
http://JavaScript.FAQTs.com/


All times are GMT. The time now is 04:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57