W
Wabiloo
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!
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!