Display Link Title Instead of URL in XSL



PHP Snippet 1:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:stmp="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:php="http://php.net/xsl" exclude-result-prefixes="php stmp">
<xsl:output method="html" indent="yes" doctype-system="about:legacy-doctype"/>
<xsl:template match="/">
<html>
<head>
<title>Goodtime HTMP Sitemap</title>
</head>
<body>
    <xsl:for-each select="/stmp:urlset/stmp:url/stmp:loc">
    <div>
        <a href="{.}">
          <xsl:value-of select="php:function('getHtmlTitle', string())"/>
        </a>
    </div>
    </xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

PHP Snippet 2:

function getHtmlTitle($url) {
    $doc = DOMDocument::loadHTMLFile($url);
    return $doc->documentElement->getElementsByTagName('title')->item(0)->textContent;
}

function SitemapHTML()
    {
        
        $xp = new XsltProcessor();
        $xp->registerPHPFunctions('getHtmlTitle');
        $xsl = new DomDocument;
        $xsl->load('parse-site-map1.xsl');

        $xp->importStylesheet($xsl);

        $xml_doc = new DomDocument;
        $xml_doc->load('sitemap1.xml');
        $xml_doc->formatOutput = TRUE;

        if ($html = $xp->transformToXml($xml_doc)) {
            echo $html;
        } else {
            return "<p>Il y a eu un problème.</p>";
        }
    }