It is difficult to offer an XSLT solution without knowing the structure of the input data, and without knowing exactly the context in which processing occurs, so this answer is based on several assumptions.
I did some research on sharepoint and found that the PublishingRollupImage
attribute can contain (or always contains) XML embedded as raw text. This will not make any difference at the time of testing, but it will have to be considered when displaying. You will have to print the result using disable-output-escaping
if you want to generate XML.
As for the test you did, @Renan is right: test="@PublishingRollupImage = ''"
test tests whether a PublishingRollupImage
attribute exists and contains the empty string, whereas simply using test="@PublishingRollupImage
"tests whether the attribute exists It's different things.
I've created this test XML, which may be similar to what you're getting where there are three <Row>
elements. One that contains a PublishingRollupImage
attribute that contains the embedded XML, another that contains the attribute with an empty string, and finally one that does not contains the attribute:
<root>
<Row ID="1" Style="Resultado-Lista"
Title="Imagem 1"
PublishingRollupImage="<img alt="" src="/PublishingImages/imagem.jpg" style="border:px solid" />" />
<Row ID="2" Style="Resultado-Lista"
Title="Imagem Faltando"
PublishingRollupImage="" />
<Row ID="3" Style="Resultado-Lista"
Title="Não é imagem" />
</root>
I have processed this source document in the style sheet below (which included the three Row
in the Rows
variable):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:variable name="Rows" select="//Row"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$Rows[1]/@Style='Resultado-Lista'">
<ul>
<xsl:for-each select="$Rows">
<li>
<a href="/{@FileRef}" title="2014-05-26 - {@Title}">
<xsl:choose>
<xsl:when test="(@PublishingRollupImage = '')">
<img src="/Util/Imagens/Conteudo/sem-imagem-noticia.jpg" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@PublishingRollupImage" disable-output-escaping="yes" />
</xsl:otherwise>
</xsl:choose>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
And the result was:
<ul>
<li>
<a href="/" title="2014-05-26 - Imagem 1"><img alt="" src="/PublishingImages/imagem.jpg" style="border:px solid" /></a>
</li>
<li>
<a href="/" title="2014-05-26 - Imagem Faltando">
<img src="/Util/Imagens/Conteudo/sem-imagem-noticia.jpg"/>
</a>
</li>
<li>
<a href="/" title="2014-05-26 - Não é imagem"/>
</li>
</ul>
I put a XSLT Fiddle here with the example code above, which you can test in real time.
See if this helps you find the solution to your problem.