XSL does not enter the correct condition

2

I have the following condition:

<xsl:when test="$Rows[1]/@Style='Resultado-Lista'">
 <ul>
  <xsl:for-each select="$Rows">
     <li>
        <a href="/{@FileRef}" title="{$Data} - {@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"  />
             </xsl:otherwise>
           </xsl:choose>
        </a>
     </li>
  </xsl:for-each>
 </ul>
</xsl:when>

In one of the results the @PublishingRollupImage field is filled, but it always enters the first condition.

I use a list of sharepoint pages to search and the field is of type " Publication Image "

I have tried to xsl:if however, I believe that I am doing the condition in the wrong way. Can anyone help me?

    
asked by anonymous 26.05.2014 / 15:29

2 answers

1

Instead of comparing, you are assigning the '' value to the PublishingRollupImage variable. To check if it is filled, just do the following:

<xsl:when test="@PublishingRollupImage">
    
26.05.2014 / 21:31
1

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="&lt;img alt=&quot;&quot; src=&quot;/PublishingImages/imagem.jpg&quot; style=&quot;border:px solid&quot; /&gt;" />
    <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.

    
26.05.2014 / 22:25