473,884 Members | 2,358 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 15537
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>Surnam e 1</lname>
<street>stree t 1</street>
</user>
<user>
<fname>Name 2</fname>
<lname>Surnam e 2</lname>
<street>stree t 2</street>
</user>
<user>
<fname>Name 3</fname>
<lname>Surnam e 3</lname>
<street>stree t 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:otherwis e>
<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:otherwis e>
<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"><x sl: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"><x sl: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="windo ws-1250"?>
<users>
<user>
<fname>Albert </fname>
<lname>Einstein </lname>
<street>stree t 1</street>
</user>
<user>
<fname>Paul</fname>
<lname>Dirac</lname>
<street>stree t 2</street>
</user>
<user>
<fname>Issack </fname>
<lname>Newton </lname>
<street>stree t 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
4422
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> <xsl:otherwise>
4
2593
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: --> <xsl:value-of select="string-length(.)" />
2
31409
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 that it would generate <Element attr=" VarValue "> What syntax do I use to do this? If I specify <Element attr=" <xsl:value-of select='$var'/> "> then the parser complains that &lt; &gt; must be used for
10
3832
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> <img class="admin" width="{$width}" src="{form:image-url}" /> The width attribute of img is always "", the $max_image_width variable is set to 200 and $width is initially set to the width of the image.
1
1614
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 number. This number i have to summarize during the whole for-each statement. At the end i should have the sum of the added numbers. Like:
2
1487
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
6323
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 been declared previously. I couldn't find a way to change it's value. It seems it is constant. Is there any alternative way? Thanks in Advance Afshar
2
2894
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 able to make a data table sortable by different headers. Right now, I've got javascript that lets you click on a column header, and then it changes the DOM of the xsl file (changes the select attribute of the xsl:sort element) and reapplies the...
0
1323
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 attributes @KEY1 and @KEY2. However the first code example only populates the 'atts' variable with the first attribute value @KEY1, when I want both: <xsl:variable name="atts"> <xsl:choose> <xsl:when test="local-name()='DELETE'">
0
9954
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10769
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10426
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9591
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5808
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
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 we have to send another system
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.