0

I have tried several things to get it work.

Here is my problem.

I have this XML content

<?xml version="1.0" encoding="UTF-8"?>
<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
  <csw:Record xmlns:dct="http://purl.org/dc/terms/" xmlns:ows="http://www.opengis.net/ows" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <dc:identifier>b6ebec90-96ac-477f-bfcf-ccef920e3e99</dc:identifier>
  <dc:title>Physiographic Map of North and Central Eurasia (Sample record, please remove!)</dc:title>
  <dct:abstract>Physiographic maps ... </dct:abstract>
  <dc:rights>copyright</dc:rights>
  <dc:language />
  <dc:source />
  <ows:BoundingBox crs="urn:ogc:def:crs:::Lambert Azimuthal Projection">
    <ows:LowerCorner>156 -3</ows:LowerCorner>
    <ows:UpperCorner>37 83</ows:UpperCorner>
  </ows:BoundingBox>
  <dc:URI protocol="image/gif" name="thumbnail">resources.get?id=14&amp;fname=phy_s.gif&amp;access=public</dc:URI>
  </csw:Record>
</csw:GetRecordByIdResponse>

and I'm trying to use the value of <dc:URI protocol="image/gif" name="thumbnail">resources.get?id=14&amp;fname=phy_s.gif&amp;access=public</dc:URI> as the src of an img tag.

Note that the value in the XML is encoded (& instead of &)

Here's the xsl I use to transform the XML to HTML

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:geonet="http://www.fao.org/geonetwork"
xmlns:ows="http://www.opengis.net/ows"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:fn="http://www.w3.org/2005/xpath-functions"   >

<xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:template match="csw:GetRecordByIdResponse">
    <html>
        <head>
            <meta charset="utf-8" />
        </head>
        <body>
                <xsl:apply-templates select="csw:Record" />
        </body>
    </html>
</xsl:template>

<xsl:template match="csw:Record">
    <h1><xsl:value-of select="dc:title" /><span class='identifier'><xsl:value-of select="dc:identifier" /></span></h1>
    <p class='description'><xsl:value-of select="dc:title" /></p>
    <ul>
        <xsl:for-each select="dc:URI">
            <xsl:if test="@name = 'thumbnail'">
                <li>
                    <xsl:value-of select="." disable-output-escaping="yes" />               
                    <xsl:element name="img">
                        <xsl:attribute name="src"><xsl:text>http://localhost:8080/geonetwork/srv/en/</xsl:text><xsl:value-of select="." disable-output-escaping="yes" /></xsl:attribute>
                    </xsl:element>  
                </li>
            </xsl:if>
        </xsl:for-each>
    </ul>
</xsl:template>

I'm using PHP to process it

<?php
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('sample.xsl');

// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);

$xml_doc = new DomDocument;
$xml_doc->loadXML(file_get_contents('sample.xml'));
// transform the XML into HTML using the XSL file
if ($html = $xp->transformToXML($xml_doc))
    echo $html;
?>

I'm still getting this output ... <li>resources.get?id=14&fname=phy_s.gif&access=public<img src="http://localhost:8080/geonetwork/srv/en/resources.get?id=14&amp;fname=phy_s.gif&amp;access=public"> </li> ... Note that the value in the src attribute still has &amp; while the other one his outputting correctly &.

Thanks in advance, Jack

jackdbernier
  • 1,542
  • 1
  • 17
  • 32

1 Answers1

1

Note that the value in the href attribute still has &amp; while the other one his outputting correctly &.

No, the correct and required writing is &amp; in href attributes within the output. I'm lazy in typing, for an explanation see the question Remove &amp from string when writing to xml in PHP and particulary this answer.

Even the other one of which you wrongfully thought it's correct (&) must be written as &amp; correctly.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836