Bonjour les amis,
J’ai une liste des cartes.
J’essai d’afficher deux cartes par ligne.
Jusqu'à maintenant c’est bon.
Voila mon programme qui marche
XML :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<cardInfo>
 
	<cards>
		<card id="111111111"/>
		<card id="222222222"/>
		<card id="3333333"/>
		<card id="4444444444444"/>
		<card id="5555555555"/>
		<card id="666"/>
		<card id="77777777777"/>
		<card id="888"/>
		<card id="9999"/>
	</cards>
</cardInfo>
XSL:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:output indent="yes"/>
	<xsl:output encoding="ISO-8859-1"/>
	<xsl:template match="cardInfo">
 
		<cards>
 
			<xsl:variable name="C" select="count(cards/@card)"/>
			<xsl:for-each select="cards/card">
				<xsl:variable name="CardValue" select="@id"/>
				<xsl:variable name="P" select="position()"/>
				<xsl:choose>
					<xsl:when test="($P) mod 2 = 1 and  $P = $C">
 
							<LineNumber>
								<xsl:value-of select="$P"/>
							</LineNumber>
							<Text>
								<xsl:value-of select="$CardValue"/>
							</Text>
					</xsl:when>
					<xsl:when test="($P) mod 2=0">
						<xsl:variable name="CardValue2">
							<xsl:for-each select="//cards/card">
								<xsl:variable name="P2" select="position()"/>
								<xsl:if test="($P2)=(($P)-1)or ($P2)=($P)">
									<xsl:value-of select="concat(@id, '-')"/>
								</xsl:if>
							</xsl:for-each>
						</xsl:variable>
						<LineNumber>
							<xsl:value-of select="$P"/>
						</LineNumber>
						<Text>
							<xsl:value-of select="$CardValue2"/>
						</Text>
					</xsl:when>
					<xsl:otherwise/>
				</xsl:choose>
			</xsl:for-each>
		</cards>
	</xsl:template>
</xsl:stylesheet>
cependant mon problème est quand la concaténation de deux ID est supérieur à 20 caractères, je ne dois pas insérer deux cartes par ligne, d'où le problème.
j'arrive à faire la même chose en java, voila un exemple du code java qui marche mais le problème en XSL, je ne peux pas modifier une variable que j'ai déclarée .
code java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public class PositionTest {
 
  private static String[] arrayOfString = {"card1111", "card2", "card3", "card444444", "card5",
          "card6", "card7", "card888888", "card9"};
  /**
   * @param args
   */
  public static void main(String[] args) {
      System.out.println("length arrayOfString = "+arrayOfString.length);
      int postionL1 = 0;
      int postionL2 = 1;
      String resGlobal = "";
      int lineNumber = 0;
      while (postionL1 <= arrayOfString.length-1) {
 
          String res = "";
          System.out.println("positionL2 "+postionL2+" positionL1 = "+postionL1);
 
//          l'algorithme est la suivante :
//              1. si la longueur de deux est supérieur à 10 donc
          String l1 = arrayOfString[postionL1];
          String l2 = "";
          if (postionL1 < arrayOfString.length-1){
              l2 = arrayOfString[postionL2];    
          }
          if (l1.length() + l2.length() <= 10){
              lineNumber = incrementValue(lineNumber, 1);
              res += l1 + (l2.length()!= 0?" - ":"")+l2+" \n";
              postionL1 = incrementValue(postionL1, 2);
              postionL2 = incrementValue(postionL2, 2);

          }else {
              lineNumber = incrementValue(lineNumber, 1);
              res += l1 + " \n";
              postionL1 = incrementValue(postionL1, 1);
              postionL2 = incrementValue(postionL2, 1);
          }
          
          System.out.println(lineNumber+ " : " +res);


          resGlobal +=res;

      }
      System.out.println(resGlobal);

  }
  private static int incrementValue(int value, int incrementValue){
      value = value+incrementValue;
      return value;
  }

}
quelqu'un peut m'aider à corriger mon code XSL.