xsl-list
[Top] [All Lists]

Re: [xsl] Xpath to node that has a parent with a certain attribute

2016-10-26 05:23:36

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

*:target is XPath 2.0 syntax selecting an element with local name "target" in 
any namespace. 

Unfortunately with PHP and libxml you're using 15-year old XML technology that 
doesn't recognize that construct.

Try Saxon/C.

Michael Kay
Saxonica



Cheers, Manuel


2016-10-25 20:44 GMT+02:00 Eliot Kimber ekimber(_at_)contrext(_dot_)com 
<mailto:ekimber(_at_)contrext(_dot_)com> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>:
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 <http://contrext.com/>
 


From: "Manuel Souto Pico terminolator(_at_)gmail(_dot_)com 
<mailto:terminolator(_at_)gmail(_dot_)com>" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
Reply-To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>>
Date: Tuesday, October 25, 2016 at 12:48 PM
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>>
Subject: [xsl] 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 <x-msg://8/-list/2528023> (by email 
<applewebdata://67E5A704-532F-4DCF-B545-AFA1EC59C82F>)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/293509> (by email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>