473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simulate a boolean flag in xslt

Hello,
As I understand it is impossible in xslt to change the value of a
variable after you assigned a value to it.

I would like to simulate a flag. For example
if something happens in template A then update my flag.
Template B reads the flag and according to its value decides to do
something.

The main idea is that template B is independent of template A, i.e.
template A does not call it directly.

Do you have any idea ?

Thank you,
Efi
Dec 25 '07 #1
2 7318
Efi Merdler wrote:
As I understand it is impossible in xslt to change the value of a
variable after you assigned a value to it.
That is true.
I would like to simulate a flag. For example
if something happens in template A then update my flag.
Template B reads the flag and according to its value decides to do
something.

The main idea is that template B is independent of template A, i.e.
template A does not call it directly.
You can pass parameters to templates e.g.
<xsl:apply-templates select="foo">
<xsl:with-param name="flag" select="true()"/>
</xsl:apply-templates>

<xsl:template match="foo">
<xsl:param name="flag" select="false()"/>
...
</xsl:template>

With XSLT 1.0 you would need to ensure that the parameter is passed on
to all templates involved, with XSLT 2.0 you could make use of a tunnel
parameter e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:output method="text"/>

<xsl:template match="/root">
<xsl:apply-templates select="foo">
<xsl:with-param name="flag" select="true()" tunnel="yes"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="foo">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="bar">
<xsl:param name="flag" select="false()" tunnel="yes"/>
<xsl:sequence select="$flag"/>
</xsl:template>

</xsl:stylesheet>

Although the template matching foo does not have an xsl:param the tunnel
parameter named flag is passed on to the template matching bar.

There are three XSLT 2.0 implementations currently, one is Saxon from
<URL:http://saxon.sourceforge.net/>, on is Altova XML tools, one is
Gestalt <URL:http://sourceforge.net/project/showfiles.php?group_id=124274>.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 26 '07 #2
A different way from passing parameters (as explained by Martin Honnen), is
to define a *global* variable, whose content is the result of calling the
template named A.

Then in template B simply reference this global variable.
Cheers,
Dimitre Novatchev

"Efi Merdler" <fo****@gmail.comwrote in message
news:92**********************************@i29g2000 prf.googlegroups.com...
Hello,
As I understand it is impossible in xslt to change the value of a
variable after you assigned a value to it.

I would like to simulate a flag. For example
if something happens in template A then update my flag.
Template B reads the flag and according to its value decides to do
something.

The main idea is that template B is independent of template A, i.e.
template A does not call it directly.

Do you have any idea ?

Thank you,
Efi

Dec 26 '07 #3

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

Similar topics

5
by: asim | last post by:
Hi if a declare a variale say Dim Flag and assing it to true a boolean value Flag = True and if i try to concatinate it with another string like mystr="<my-str>" & Flag & "</my-str>" and if...
4
by: Bradley Plett | last post by:
I have what should be a trivial problem. I am using XMLSerializer to serialize an object. It serializes boolean values as "True" and "False". I then want to use an XSLT on this XML, and I want...
16
by: Ian Tuomi | last post by:
How can I define a boolean value in c? (an value that can only be either 1 or 0) I feel bad for the memory loss when declaring ints for variables that do not need that much memory. -- Ian Tuomi...
4
by: Joe HM | last post by:
Hello - I realize that there is no more IsMissing function in VB.NET but how can I have a boolean argument that is optional and in the code I need to determine whether it was passed it or not? ...
5
by: vaibhav | last post by:
Hi I am writing a wrapper over the existing xalan libraries. I have to pass xsl parameters to the xslt processor at run time. These paramters are later referenced in the stylesheet .The xalan cpp...
76
by: KimmoA | last post by:
First of all: I love C and think that it's beautiful. However, there is at least one MAJOR flaw: the lack of a boolean type. OK. Some of you might refer to C99 and its _Bool (what's up with the...
4
by: moondaddy | last post by:
I'm new to c# and want to know the preferred way to reverse a Boolean value. for example: in vb I can do this: dim flag as Boolean
2
by: Daniel | last post by:
I have a class similar to this: class MyThread(threading.Thread): def __init__(self): self.terminated = False def run(self): while not self.terminated:
11
by: KiranJyothi | last post by:
Hello All, I am writing a code in C where I have to use the Boolean data type. I am doing - typedef int flag; #define FALSE 0 #define TRUE 1 void main()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.