<?php
$xslStr = '<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="nl"><xsl:text>
</xsl:text></xsl:variable>
<xsl:template xml:space="default" match="/">
<xsl:text>cities:</xsl:text>
<xsl:value-of select="$nl"/>
<xsl:for-each select="List/City">
<xsl:value-of select="concat(\' id\', CityId)"/>: <xsl:value-of select="Name" />
<xsl:value-of select="$nl"/>
</xsl:for-each>
</xsl:template>
<xsl:output method="text" media-type="text/yml" />
</xsl:stylesheet>';
$xsl = new DOMDocument();
$xsl->loadXML($xslStr);
$xml = new DOMDocument();
$xml->load(__DIR__ . '/city.xml');
$p = new XSLTProcessor();
$p->importStylesheet($xsl);
$xml = $p->transformToXML($xml);
echo '<pre>' . $xml . '</pre>';
cities: id1: South Park id2: Springfield id3: Quahog