I need to return the areas connected with the town placeid attribute of an XML document. The town placeid is a variable equal to a current page variable $x.


How can I return the areas for each using simpleXML/XPATH?


<town placeid="" />





I'm not sure if I understood your requirement correctly, but have posted the below with an assumption:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:output method="xml"/>

<xsl:variable name="x" select="'Plano'"/>

<xsl:template match="/">
			<xsl:for-each select="//town[@placeid = $x]">
				<xsl:copy-of select="following-sibling::areas[1]"/>


If thats not what you want, please post a minimal input XML and the required output XML.

Thanks Mrame, your answer has greatly helped.

I'm using simpleXML/ XPATH/ PHP to pull the contents of the XML (I'm not using XSL). I've got as far as printing the array - The following code prints this:

$area = $xml->xpath("/country/city/town[@placeid=$x]/following-sibling::areas[1]");

and outputs:
Array ( [0] => SimpleXMLElement Object ( [area] => Array ( [0] => A [1] => B [2] => C ) ) )

but how do I only print the area content (with a line break or <br/> if possible) e.g.

Any help would be great.

I really don't have any idea about PHP. From an assumption I think $area has


in its memory. So use for-each to work on each <area> (for-each areas/area) and get the value in separate line.

I think this will work.

Thanks Mrame! foreach worked, really appreciate your help.