xsl-list
[Top] [All Lists]

Re: [xsl] update value of variable in for-each loop

2014-04-08 15:52:04
On 08/04/2014 21:18, henry human wrote:
sorry Michael, David
I was little bustling!
  hope this below is more clear now.
The varable value should be updated



      <xsl:variable name="foo"/>

This variable isn't used.


  <xsl:for-each select=”partiotion/files/file[@name=’xx’ or name=’xy’ or name=’asd’ or  
……….. ”>
        <xsl:variable name="foo">
                      <xsl:for-each select="data">
                          <xsl:choose>
                              <xsl:when test="contains(elements/elementA '1234) or contains(elements/package/id '55) or 
contains(elements/category/id, '67)" or contains(………….">

                                  <xsl:value-of select="1"/>
                              </xsl:when>
                              <xsl:otherwise>
                                  <xsl:value-of select="0"/>
                              </xsl:otherwise>
                          </xsl:choose>
                      </xsl:for-each>
                 </xsl:variable>

This variable is only used once, on the line below so really no point in havin it, as mentioned before $foo will be a document node with a text node child that is a sequence of 0 and 1.
                                


                          <xsl:choose>
                              <xsl:when test="$foo = 1">

So it will only be equal to 1 if all but the last value in the loop above gave 1 ir if $foo is 0000000000000000000001 But it seems a pretty strange thing to be testing.

                                 //doSomething
                              </xsl:when>
                              <xsl:otherwise>
                                  //doNothing
                              </xsl:otherwise>
                          </xsl:choose>
      </xsl:for-each


As a wild guess, perhaps you didn't want any variable at all and wanted all of the above replaced by


<xsl:if test="(partiotion/files/file[@name=’xx’ or name=’xy’ or name=’asd’ or ……….. )/ data/(contains(elements/elementA '1234) or contains(elements/package/id '55) or contains(elements/category/id, '67)" or contains(………….))">
 do something
</xsl:if>


David

--
google plus: https:/profiles.google.com/d.p.carlisle

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--