[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] update value of variable in for-each loop
From: henry human <henry_human@xxxxxxxx>
Date: Tue, 8 Apr 2014 21:49:00 +0100 (BST)

When I run this code the output of the variable foo is never 1 or 0 as I
expect but either 0011 or 11 or 0001

brg
--------------------------------------------
henry human <henry_human@xxxxxxxx> schrieb am Di, 8.4.2014:

 Betreff: Re: [xsl] update  value of variable in for-each loop
 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
 Datum: Dienstag, 8. April, 2014 22:18 Uhr

 sorry Michael, David
 I was little bustling!
  hope
 this below is more clear now.
 The varable
 value should be updated



 B 
 B B B <xsl:variable name="foo"/>B 
 B  B  B 
  <xsl:for-each
 select=bpartiotion/files/file[@name=bxxb or
 name=bxyb or name=basdb orB  b&b&b&.. b>
 B  B  B B B <xsl:variable
 name="foo">
 B  B  B  B  B  B 
 B  B  B  B B B <xsl:for-each
 select="data">
 B  B  B  B  B 
 B  B  B  B  B  B  B B B <xsl:choose>
 B  B  B  B  B  B  B  B  B  B  B  B  B 
 B B B <xsl:when
 test="contains(elements/elementA '1234) or
 contains(elements/package/id '55) or
 contains(elements/category/id, '67)" or
 contains(b&b&b&b&.">

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


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

 B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
 //doSomething
 B  B  B  B  B  B  B  B  B  B 
 B  B  B  B B B </xsl:when>
 B 
 B  B  B  B  B  B  B  B  B  B  B  B 
 B B B <xsl:otherwise>
 B  B  B 
 B  B  B  B  B  B  B  B  B  B  B  B 
 B B B //doNothing
 B  B  B  B  B  B 
 B  B  B  B  B  B  B  B B B </xsl:otherwise>
 B  B  B  B  B  B  B  B  B  B  B 
 B B B </xsl:choose>
 B 
 B B B </xsl:for-each
 --------------------------------------------
 Michael Kay <mike@xxxxxxxxxxxx>
 schrieb am Di, 8.4.2014:


 Betreff: Re: [xsl] updateB  value of variable in for-each
 loop
  An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
  Datum: Dienstag, 8. April, 2014 21:56 Uhr

  What are you actually
  trying to achieve? If you simply want to test
 whether one of
  the elementA elements
 contains "1234", you can
  write

  <xsl:if

 test="elements/elementA[contains(.,

 '1234')]">
  B B B ...
  </xsl:if>

  But I can't tell if that's what you
 are
  trying to do because you don't say.
 You've been
  using this list long enough
 to know that most of us have
  difficulty
 reverse-engineering requirements from non-working
  code.


 Michael Kay
  Saxonica


  On 8
  Apr
 2014, at 20:13, henry human <henry_human@xxxxxxxx>
  wrote:

  >
 Hi
  > I have a for-each loop
  > inside for-each I try to test a
  variable:
  > //if
 statement
  > <xsl:if test="$foo
 =
  1">
  > //do
 nothing
  >
  >
  >
  > The varibale
  definition:
  > B B B 
 <xsl:variable

 name="foo"/>
  > B B B 
 B B B 
  <xsl:variable
 name="foo">
  > B B B  B B B 
 B B B  B B B  B B B 
  <xsl:for-each
 select="data">
  > B B B 
 B B B  B B B  B B B  B B B  B B B 

 <xsl:choose>
  > B B B  B B B 
 B B B 
  B B B  B B B  B B B  B B B 
 <xsl:when

 test="contains(elements/elementA

 '1234)">
  >

 > B B B  B B B  B B B  B B B  B B B  B B B 
  B B B  B B B  <xsl:value-of
 select="1"/>
  > B B B 
 B B B  B B B  B B B  B B B  B B B 
  B B B 
 </xsl:when>
  > B B B  B B B 
  B B B  B B B  B B B  B B B  B B B 
 <xsl:otherwise>
  > B B B  B B B 
 B B B  B B B  B B B  B B B 
  B B B  B B B 
 <xsl:value-of select="0"/>

 > B B B  B B B  B B B  B B B  B B B  B B B 
  B B B  </xsl:otherwise>

 > B B B 
  B B B  B B B  B B B  B B B 
 B B B  </xsl:choose>
  > B B B 
 B B B  B B B  B B B  B B B 

 </xsl:for-each>
  > B B B  B B B 
  B B B  B B B  </xsl:variable>
  >
  B B B  B B B  B B B 
 B B B 
  > B B B 
  B B B 
 B B B  B B B 
  > B B B  B B B 
  B B B  B B B 
  >
 Unfortunatelly the value
  of the varable foo
 is either 001 , 011,00011 and so one and

 the if statement works never correctB  !

 > I even defined the varable as a xs:integer
  type or as below , but ever the value is never
 a 1B  orB 
  0
  >
  >
  <xsl:variable
 name="foo"B 

 select='1'"/>
  >
 B B B 
  B B B  <xsl:variable
 name="foo">
  > B B B  B B B 
 B B B  B B B  B B B 
  <xsl:for-each
 select="data">
  > B B B 
 B B B  B B B  B B B  B B B  B B B 

 <xsl:choose>
  > B B B  B B B 
 B B B 
  B B B  B B B  B B B  B B B 
 <xsl:when

 test="contains(elements/elementA,

 '1234)">
  >

 > B B B  B B B  B B B  B B B  B B B  B B B 
  B B B  B B B  <xsl:value-of
  select="'1'"/>
  >
  B B B  B B B  B B B 
 B B B  B B B  B B B  B B B 

 </xsl:when>
  > B B B  B B B 
 B B B 
  B B B  B B B  B B B  B B B 
 <xsl:otherwise>
  > B B B  B B B 
 B B B  B B B  B B B  B B B 
  B B B  B B B 
 <xsl:value-of

 select="'0'"/>
  >
  B B B  B B B  B B B  B B B  B B B  B B B 
 B B B 
  </xsl:otherwise>
  > B B B  B B B 
  B B B 
 B B B  B B B  B B B  </xsl:choose>

 > B B B  B B B  B B B  B B B  B B B 

 </xsl:for-each>
  > B B B  B B B 
  B B B  B B B  </xsl:variable>
  >
  B B B  B B B  B B B 
 B B B 
  > Brg
  >
 Henry


Current Thread