Search

I got the following xml:

<entry id="1">
 <title></title>
 <gallery>
  <item><image></image></item>
</entry>
<entry id="2">
 <title></title>
 <gallery>
  <item><image></image></item>
  <item><image></image></item>
</entry>

The xslt is as follow:

<xsl:for-each select="gallery/item">
 <xsl:value-of select="entry/title">
 <xsl:value-of select="image">
</xsl:for-each>

Wanted result:

Title 1 image

Title 2 image

Title 2 image

But the title is out of the context form gallery/item so it only gives me Title 1.

I thought entry/preceding::title would do the trick. But it doesn't.

Try this: http://xpathr.com/view/2940230/faf9de4b4d0f148b13f81825392809ac8b6216c1/

My logic is a bit different so to answer your initial question how to match the title from gallery/item: you'll first have to move up to the entry using ancestor::entry and then go back down to titleancestor::entry/title or ../../title in this specific case.

Can't try it at the moment but this seems the solution.

Thanks Nils. I'll try it tonight

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details