Topic
  • 3 replies
  • Latest Post - ‏2010-06-02T07:59:42Z by SystemAdmin
repie
repie
2 Posts

Pinned topic simple xpath syntax question

‏2010-06-01T14:45:14Z |
I am using xpath through a php application.


$xml = simplexml_load_file(
"/somePath/Adressen.xml"); $data = $xml->xpath(
"//adressname[contains(.,'Ci')]"); foreach( $data as $t)
{ echo $t.
"<br/>"; 
}


This works but gives me some duplicate entries.

I've read that there is a distinct-values() function in XLST2.0 but php only supports the old 1.0 flavour and this function is not available.
I've read about this type of work around:

/thing[not(@result = preceding-sibling::thing/@result)]


but I do not know (I'm very new to xpath) how to implement this in my previous xpath query:


//adressname[contains(.,'Ci')]


Can someone put me on the way?

Thanks
Updated on 2010-06-02T07:59:42Z at 2010-06-02T07:59:42Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    746 Posts

    Re: simple xpath syntax question

    ‏2010-06-02T07:48:50Z  
    You can do this.
    
    $data = $xml->xpath(
    "//adressname[contains(.,'Ci') and not (text()=preceding-sibling::adressname/text()]");
    
  • repie
    repie
    2 Posts

    Re: simple xpath syntax question

    ‏2010-06-02T07:53:26Z  
    You can do this.
    <pre class="jive-pre"> $data = $xml->xpath( "//adressname[contains(.,'Ci') and not (text()=preceding-sibling::adressname/text()]"); </pre>
    It didn't work...

    Says: xmlXPathEval: evaluation failed
  • SystemAdmin
    SystemAdmin
    746 Posts

    Re: simple xpath syntax question

    ‏2010-06-02T07:59:42Z  
    • repie
    • ‏2010-06-02T07:53:26Z
    It didn't work...

    Says: xmlXPathEval: evaluation failed
    There is typo of balancing parenthesis if you don't mind!
    
    $data = $xml->xpath(
    "//adressname[contains(.,'Ci') and not(./text()=preceding-sibling::adressname/text())]");