M
Max
Hi!
I have a problem with an XSL transformation. This is the XML file to
transform: there's an "article" with one element of type "text". There
are two nested elements of type "image" and "text":
<article>
<element type="text ">
<![CDATA[Some introductory text]]>
<element name="photo" type="image" ext="jpg"/>
<element type="text ">
<![CDATA[Text related to the image]]>
</element>
</element>
</article>
My goal is to print:
Some introductory text
<img src="photo.jpg" />.
Text related to the image.
This is the XSL:
<xsl:template match="/">
<xsl:apply-templates select="/article/element[@type = 'text]"/>
<xsl:apply-templates select="article/element/element[@type =
'image']"/>
</xsl:template>
<xsl:template match="article/element[@type = 'text']">
<xsl:value-of select="." />
</xsl:template>
<xsl:template match="/article/element/element[@type = 'image']">
<img src="{@name}.{@ext}" />.
<xsl:apply-templates select="../element[@type = 'text-body']"/>
</xsl:template>
The problem is that the XSL prints the first and the second text
together. This is the result of the XSL:
Some introductory text. Text related to the image.
<img src="photo.jpg" />.
Text related to the image.
How can I solve the problem? Thanks!
Bye, Max
I have a problem with an XSL transformation. This is the XML file to
transform: there's an "article" with one element of type "text". There
are two nested elements of type "image" and "text":
<article>
<element type="text ">
<![CDATA[Some introductory text]]>
<element name="photo" type="image" ext="jpg"/>
<element type="text ">
<![CDATA[Text related to the image]]>
</element>
</element>
</article>
My goal is to print:
Some introductory text
<img src="photo.jpg" />.
Text related to the image.
This is the XSL:
<xsl:template match="/">
<xsl:apply-templates select="/article/element[@type = 'text]"/>
<xsl:apply-templates select="article/element/element[@type =
'image']"/>
</xsl:template>
<xsl:template match="article/element[@type = 'text']">
<xsl:value-of select="." />
</xsl:template>
<xsl:template match="/article/element/element[@type = 'image']">
<img src="{@name}.{@ext}" />.
<xsl:apply-templates select="../element[@type = 'text-body']"/>
</xsl:template>
The problem is that the XSL prints the first and the second text
together. This is the result of the XSL:
Some introductory text. Text related to the image.
<img src="photo.jpg" />.
Text related to the image.
How can I solve the problem? Thanks!
Bye, Max