I have found many posts which concern my problem but the solutions don't work.
I have many XML elements in my input and I want generate a KML file. For the KML description I use CDATA. In this CDATA I try to put an <img>
.
So my XSL:
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:text disable-output-escaping="yes">
<p>The <a href="http://en.wikipedia.org/wiki/Fremont_Troll">Fremont Troll</a> is a large concrete sculpture <br/>
of the mythical troll who lives under the bridge.</p>
<p>The troll is holding a Volkswagen bug in his hand.</p>
<img src="http://client.thomasblasig.fr/KML_images
</xsl:text>
<xsl:variable name="link_image" select="$images/circuits/circuit[@id=$id_circuit]/image[@etape=$id_etape]/lien"></xsl:variable>
<xsl:variable name="new_link_image" select="replace($link_image, './', '/')"></xsl:variable>
<xsl:value-of select="translate($new_link_image, ' ', '')"></xsl:value-of>
<xsl:text disable-output-escaping="yes">
"></img>
</xsl:text>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
The code produces this result:
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Placemark>
<name>Etape n° 1 : Avenue Joliot Curie</name>
<description>
<![CDATA[
<p>The <a href="http://en.wikipedia.org/wiki/Fremont_Troll">Fremont Troll</a> is a large concrete sculpture <br/> of the mythical troll who lives under the bridge.</p> <p>The troll is holding a Volkswagen bug in his hand.</p> <img src="http://client.thomasblasig.fr/KML_images /image/02.jpg "></img>
]]>
</description>
<Point>
<coordinates>-74.006393,40.714172,0</coordinates>
</Point>
</Placemark>
As you can see, there are whitespaces between my <xsl:text>
and my <xsl:valueof>
. How can I remove them?
I am guessing the whitespace you are talking about, is the whitespaces occur in the img
tag in your output:
<img src="http://client.thomasblasig.fr/KML_images /image/02.jpg ">
If this is the case, it is not the whitespace between the xsl:text
and xsl:value-of
that is causing the issue (as whitespace-only nodes in the XSLT are not significant), but the whitespace within the xsl:text
itself
So, this xsl:text
...
<xsl:text disable-output-escaping="yes">
"></img>
</xsl:text>
... really needs to be written like this:
<xsl:text disable-output-escaping="yes">"></img></xsl:text>
And similarly for the first xsl:text
, it needs to end like this...
<img src="http://client.thomasblasig.fr/KML_images</xsl:text>
Note that you might consider re-writing your XSLT to be like this, to give it a semblance of readability
<description>
<![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Fremont_Troll">Fremont Troll</a> is a large concrete sculpture <br/>
of the mythical troll who lives under the bridge.</p>
<p>The troll is holding a Volkswagen bug in his hand.</p>
<img src="http://client.thomasblasig.fr/KML_images]]><xsl:value-of select="translate($new_link_image, ' ', '')" /><![CDATA["></img>]]>
</description>
(This would probably have to be combined with the cdata-section-elements
attribute on the xsl:output
element)
<xsl:output method="xml" indent="yes" cdata-section-elements="description" />