xsl-list
[Top] [All Lists]

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

2016-10-25 13:39:17
Thanks, Michael.

This seems to work:

$xliff->xpath('//target[parent::trans-unit[@id="xxx"]]')[0]->__toString()

Cheers, Manuel


2016-10-25 18:15 GMT+02:00 Michael Kay mike(_at_)saxonica(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>:

Both your XPath expressions return a node (the <target> element).

If you want to return a string (the string value of the <target> element)
then wrap a call to string(...) around your current expression.

Michael Kay
Saxonica



On 25 Oct 2016, at 17:02, Manuel Souto Pico terminolator(_at_)gmail(_dot_)com 
<
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

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/293509> (by email)


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/2528023> (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>