[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Xpath to node that has a parent with a certain at

Subject: Re: Xpath to node that has a parent with a certain attribute
From: "Manuel Souto Pico terminolator@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Oct 2016 10:04:49 -0000
Re:  Xpath to node that has a parent with a certain  at
Thanks, Eliot.

Unfortunately none of your suggestions work. I get
*Warning*: SimpleXMLElement::xpath(): Invalid expression
bool(false)

As I said in my previous email, the expression below seems to work,
following Michael's tip:
$xliff->xpath('//target[parent::trans-unit[@id="xxx"]]')[0]->__toString()

However, I'm curious about (and not familiar with) the *: Could you explain
what it means? Thanks.

Cheers, Manuel


2016-10-25 20:44 GMT+02:00 Eliot Kimber ekimber@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>:

> Most like the elements are in a namespace, so your match expressions will
> not match.
>
> You can test that by changing "//target[parent::trans-unit[@id="xxx"]]"
> to //*:target[parent::*:trans-unit[@id="xxx"]]
>
> If the @id value will be unique within the document then you can do
> something like:
>
> //*[@id = 'xxx']/*:target
>
> Also, since you know the structure, you can replace "//", which is very
> inefficient, with "/*/*/*" (if I've counted the ancestor levels correctly).
>
> Cheers,
>
> Eliot
> --
> Eliot Kimber
> http://contrext.com
>
>
>
> From: "Manuel Souto Pico terminolator@xxxxxxxxx" <xsl-list-service@lists.
> mulberrytech.com>
> Reply-To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Date: Tuesday, October 25, 2016 at 12:48 PM
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject:  Xpath to node that has a parent with a certain attribute
>
> Hi there,
>
> I'm struggling to match a node where the parent has a particular id,
> perhaps someone can help me.
>
> This is my data:
>
> <xliff>
>   <file>
>     <header/>
>     <body>
>     (...)
>       <trans-unit id="xxx>
>         <source xml:lang="en">foo</source>
>         <target xml:lang="sl" state="zzz">bar</target>
>       </trans-unit>
>
> I have parsed the file and I am trying expressions
>
> $xliff->xpath('//target[parent::trans-unit[@id="xxx"]]')
>
> and
>
> $xliff->xpath('//trans-unit[@id="xxx"]/target')
>
> but they both give me the same result:
>
> array(1) {
>   [0]=>
>   object(SimpleXMLElement)#8 (1) {
>     ["@attributes"]=>
>     array(1) {
>       ["state"]=>
>       string(22) "zzz"
>     }
>   }
> }
>
> My expected result is "bar"
>
> What I doing wrong?
>
> I'm doing this in php 5.5.11 with libxml Version 2.9.1.
>
> Thank you so much.
> Cheers, Manuel
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://-list/1278982> (by email)
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/2528023> (by
> email <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.