To select different attribute values, you can use this XPath:
/page/tab[not(@dim=preceding-sibling::tab/@dim)]/@dim
A possible XSLT template would be
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:for-each select="/page/tab[not(@dim=preceding-sibling::tab/@dim)]/@dim"> <xsl:sort select="." data-type="number"/> <xsl:value-of select="concat(., substring(',', 2 - (position() != last())))"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
To convert the source stylesheet document to PHP , you can use:
$xml = new DOMDocument; $xml->load('collection.xml'); $xsl = new DOMDocument; $xsl->load('collection.xsl'); $proc = new XSLTProcessor; $proc->importStyleSheet($xsl); echo $proc->transformToXML($xml);
This will give 30.40.70 output.
You can achieve the same without XSLT by simply doing:
$page = simplexml_load_file('NewFile.xml'); $dims = $page->xpath('/page/tab[not(@dim=preceding-sibling::tab/@dim)]/@dim'); $dims = array_map('strval', $dims); sort($dims); echo implode(',', $dims);
Also see
source share