Fernando Correia
Fernando Correia

Reputation: 27

Xpath mislead Expression

<?xml version="1.0" encoding="UTF-8"?>
<Matriculas>
   <Matricula IdPortagem=" 1,0">
      <LicensePlate>50-PX-53</LicensePlate>
      <EntryDate>2016-11-11 19:02:24</EntryDate>
      <ExitDate>2016-11-11 19:13:39</ExitDate>
      <EntryPoint>Angeiras S-N</EntryPoint>
      <ExitPoint>Povoa S-N</ExitPoint>
      <Value>2,0</Value>
      <IsPayed>N</IsPayed>
      <PaymentDate />
   </Matricula>
   <Matricula IdPortagem=" 2,0">
      <LicensePlate>50-PX-53</LicensePlate>
      <EntryDate>2016-11-11 17:27:05</EntryDate>
      <ExitDate>2016-11-11 17:27:05</ExitDate>
      <EntryPoint>ER1-18</EntryPoint>
      <ExitPoint>ER1-18</ExitPoint>
      <Value>0,45</Value>
      <IsPayed>N</IsPayed>
      <PaymentDate />
   </Matricula>
   <Matricula IdPortagem=" 3,0">
      <LicensePlate>50-PX-53</LicensePlate>
      <EntryDate>2016-11-11 12:48:36</EntryDate>
      <ExitDate>2016-11-11 12:48:36</ExitDate>
      <EntryPoint>Miramar</EntryPoint>
      <ExitPoint>Miramar</ExitPoint>
      <Value>0,45</Value>
      <IsPayed>N</IsPayed>
      <PaymentDate />
   </Matricula>
   <Matricula IdPortagem=" 4,0">
      <LicensePlate>50-PX-53</LicensePlate>
      <EntryDate>2016-11-10 21:34:31</EntryDate>
      <ExitDate>2016-11-10 21:34:31</ExitDate>
      <EntryPoint>Povoa S-N</EntryPoint>
      <ExitPoint>Povoa S-N</ExitPoint>
      <Value>1,1</Value>
      <IsPayed>N</IsPayed>
      <PaymentDate />
   </Matricula>
</Matriculas>

So I have this small XML here and I'm trying to get the EntryPoint of the Matricula with a Value bigger than 3.

I'm using this expression

/Matriculas//Matricula[Value>3,0]/EntryPoint

And it seems I'm doing something wrong... can anyone help me please?

Upvotes: 1

Views: 57

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116992

I'm trying to get the EntryPoint of the Matricula with a Value bigger than 3.

The problem here is that you are trying to compare two numbers - but XPath/XSLT expects numbers to use . dot as the decimal separator. Values using decimal comma are not considered to be numbers.

Try instead:

/Matriculas//Matricula[translate(Value, ',', '.') > 3]/EntryPoint

The above will work with XPath/XSLT 1.0. To make it future-proof, use:

/Matriculas//Matricula[number(translate(Value, ',', '.')) > 3]/EntryPoint

Of course, it would help if your input example actually contained a Matricula with a Value larger than 3.

Upvotes: 1

Related Questions