It is difficult to offer a solution in XSLT without knowing the structure of the input data, and without knowing exactly the context in which the processing takes place, so this response is based on several assumptions.
I did some research on Sharepoint and found that attribute PublishingRollupImage
can contain (or always contains) embedded XML as raw text. This will make no difference when testing, but 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: the test test="@PublishingRollupImage = ''"
test whether an attribute PublishingRollupImage
exists and contains the empty string, while simply using test="@PublishingRollupImage
" test whether the attribute exists. Are different things.
I created this test XML, which may be similar to what you are getting in that there are three elements <Row>
. One that contains an attribute PublishingRollupImage
containing embedded XML, another that contains the attribute with an empty string, and finally one that nay 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 processed this source document in the style sheet below (which included the three Row
in the variable Rows
):
<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 to find the solution to your problem.
There are several factors that can cause an element not to be selected, among them the context and namespaces. Please edit your query to include the source XML (or a fragment, including the hierarchy and root elements) and also an entire template of your XSL (if possible the entire XSLT doc, or at least the relevant start and templates).
– helderdarocha
I exemplified it better. I hope it helps. I removed only a few variable calls that do not influence the final result
– Luanna Iozzi
The ideal would be to see the XML code. And more of XSLT that shows what is the contents of the variable
$Rows
since the attribute you want is in that context. I can try to reproduce the problem if you include more information (maybe all of XSLT and a snippet of XML-source that contains the data that is not appearing)– helderdarocha
Unfortunately I can not inform you the full XML as it is Sharepoint and I do not have access to all the content. XSLT is very extensive and there is no need to add it here, just the call of the style I am assigning in the library query, which in this case is the "Result-List"
– Luanna Iozzi
What is the value of the variable
$Rows
? What is the context of your template? What’s onmatch
his?– helderdarocha
The problem is not $Rows, as there are other values within this
<xsl:for-each>
and the data is returned correctly. Maybe the problem is in the validation of the "Publication Image" column, but unfortunately, I haven’t found what it might be causing. I also exported Webpart and added in the Commonviewfields field the @Publishingrollupimage column (if in doubt) and even then it is not displayed– Luanna Iozzi