473,503 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl:variable increment

G.
How to increment global xsl:variable?

I've daclared variable:

<xsl:variable name="my-var" select="0" />

Somewhere else I do something like this:

<xsl:variable name="my-var" select="$my-var +1" />

but this creates new local variable and initialize it with value of global
variable.

How to increment xsl:variables? Is it even possible?

G.

Jul 20 '05 #1
8 15504
On 09/02/2004, around 11:54, G. wrote:
G> How to increment global xsl:variable?
Basically, you don't.

G> Is it even possible?
Nope.

You might want to look at (a) rewriting you transform without the
variable or (b) look at writing a recursive transformation.

--
Stuart
I used to work in a blanket factory, but it folded.

Jul 20 '05 #2
G.
I was warried about that. I have to change my XSLT.
Thanks.

G.
Jul 20 '05 #3
G.
So, how would you solve problem like that.

I've got XML file with presons data (names and addresses). For example:

<users>
<user>
<fname>Name 1</fname>
<lname>Surname 1</lname>
<street>street 1</street>
</user>
<user>
<fname>Name 2</fname>
<lname>Surname 2</lname>
<street>street 2</street>
</user>
<user>
<fname>Name 3</fname>
<lname>Surname 3</lname>
<street>street 3</street>
</user>
</users>

Using this file, I have to generate PDF with envelope labels. Label sheet
have two columns. If users count will be an even number, there will be no
problem. If the users number will be odd number there will be a problem. How
to slove it?

Regards,
G.

Jul 20 '05 #4
On 09/02/2004, around 14:33, G. wrote:

If users count will be an even number, there will be no
G> problem. If the users number will be odd number there will be a problem.How
G> to slove it?

<xsl:choose>
<xsl:when test="count(//user) mod 2 = 0">
<xsl:apply-templates mode='even'/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode='odd'/>
</xsl:otherwise>
</xsl:choose>

--
Stuart
Local Area Network in Australia: the LAN down under.

Jul 20 '05 #5
G.
Great, thanks. I have to read more about XSLT.

G.
Jul 20 '05 #6
G.
<xsl:choose>
<xsl:when test="count(//user) mod 2 = 0">
<xsl:apply-templates mode='even'/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode='odd'/>
</xsl:otherwise>
</xsl:choose>

I have used

<xsl:when test="(position() mod 2)= 0">

Your solution did't work at my computer. Why? I don't know.

Now I wonder how to start write templates:

I've got

<xsl:template match="user" mode="even">
<fo:table-row>
<fo:table-cell background-color="green">
<fo:block text-align="left" text-indent="2pt"><xsl:value-of
select="fname"/> </fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

<xsl:template match="user" mode="odd">
<fo:table-row>
<fo:table-cell background-color="orange">
<fo:block text-align="left" text-indent="2pt"><xsl:value-of
select="fname"/></fo:block>
</fo:table-cell>
</fo:table-row>

In 'odd mode' I shall start new table row. In 'even mode' I should end the
row. But the XML document won't be valid. How to rewrite the code to display
user envelope labels in two columns.

G.
Jul 20 '05 #7
On 10/02/2004, around 14:51, G. wrote:

G> Your solution did't work at my computer. Why? I don't know.
It works here although that's using my count() version rather than
position().

G> In 'odd mode' I shall start new table row. In 'even mode' I should end the
G> row. But the XML document won't be valid. How to rewrite the code to display
G> user envelope labels in two columns.
Can't you write a 'dummy' entry for the odd one?
--
Stuart
Error: Bad command or file name! Go stand in the corner.

Jul 20 '05 #8
G.
Sample input XML file:

<?xml version="1.0" encoding="windows-1250"?>
<users>
<user>
<fname>Albert</fname>
<lname>Einstein</lname>
<street>street 1</street>
</user>
<user>
<fname>Paul</fname>
<lname>Dirac</lname>
<street>street 2</street>
</user>
<user>
<fname>Issack</fname>
<lname>Newton</lname>
<street>street 3</street>
</user>
</users>
Using FOP and XSLT I would like to have PDF (!), that contains envelope
labels. There will be ten envelopes on each page. I think it will be the
best to put it in table - 2 colums and 5 rows. 1st row, 1st colum will
contain Albert Einstein name adn adres; 1st, 2nd column will contain Paul
Dirac; 2nd row 1st column will contain Newtons' data.

G.
P.S. XSLT is like atomic bomb. I fell it is powerful, but I can't have a
full contron on it (yet ;-)).
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4399
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case"> <xsl:variable name="test" select="0"/> </xsl:when>...
4
2569
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each select="//q"> <!-- the length of each node is compute with:...
2
31345
by: Richard | last post by:
Suppose I create a variable named "var" such as: <xsl:variable name="var">VarValue</xsl:variable> and then I want to insert its value into an attribute <Element attr=" {the value of var} "> so...
10
3794
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable name="width" select="$max_image_width"/> </xsl:if>...
1
1596
by: schaf | last post by:
Hello NG ! I have a big problem. I would like to go through a xml file in a xsl:for-each statement. for-each entry (ID) in the XML file i would like to call an xsl:function, which returns a...
2
1459
by: sucheta.phatak | last post by:
Hello, I am trying to use XSLT. Here is the problem that I am facing. My XML file: <Book level="1" name="Mapplicationtoc1"> ....... Some more tags </Book>
5
6300
by: Afshar Mohebbi | last post by:
Hi everybody there, I've declared a <xsl:variable name="something" select="999"/> in my xslt and when I want to set another value in it (with same syntax) I get error the variable "something" has...
2
2860
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
0
1298
by: Markchivs | last post by:
Hi all, I wonder if anyone can shed any light on this problem for me? In the following code I'm trying to set a variable called 'atts' with a node set of attributes which will include the...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.