how to display images with xsl with the img src of the xml file

2

I have for example the XSL code:

<xsl:for-each select="//*">
  <xsl:for-each select="imagem">
    <img>
      <xsl:attribute name="src">
        <xsl:value-of select="."/>
      </xsl:attribute>
    </img>
  </xsl:for-each>
</xsl:for-each> 

I have for example following xml code:

<?xml version="1.0" ?>
<imagens>
<imagem>
    <png id="1">img1.png</png>
    <png id="2">img2.png</png>
    <png id="3">img3.png</png>
    <png id="4">img4.png</png>
    <png id="5">img5.png</png>
</imagem>
<imagem>
    <png id="1">img6.png</png>
    <png id="2">img7.png</png>
    <png id="3">img8.png</png>
    <png id="4">img9.png</png>
    <png id="5">img10.png</png>
</imagem>

I'm trying to make this code turn into something like this:

<img src="img1.png"><img src="img2.png"><!--E assim por diante-->

But it looks like this:

<img src="img1.pngimg2.pngimg3.pngimg4.pngimg5.png">

Does anyone have any idea how to solve it?

    
asked by anonymous 01.04.2014 / 21:00

2 answers

1

The ideal is to select the element you want using a template that will be called recursively while the document nodes are processed. The XSL document below does exactly what you want without using for-each :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="png">
        <img src="{.}" />
    </xsl:template>

</xsl:stylesheet>

Result:

<img src="img1.png"><img src="img2.png"> ... <img src="img10.png">
    
03.04.2014 / 03:58
0

Try the following:

  <xsl:for-each select="//**">
    <tr>
      <td>
        <xsl:value-of select="imagem"/>
      </td>
      <td>
        <xsl:element name="imagem">
          <xsl:attribute name="src">
            <xsl:value-of select="png"/>
          </xsl:attribute>
          <xsl:attribute name="align">left</xsl:attribute>
        </xsl:element>
      </td>
    </tr>
  </xsl:for-each>
</table>

    
01.04.2014 / 21:26