Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Simulate a boolean flag in xslt

Reply
Thread Tools

Simulate a boolean flag in xslt

 
 
Efi Merdler
Guest
Posts: n/a
 
      12-25-2007
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-26-2007
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">
<xslaram 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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xslutput 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">
<xslaram name="flag" select="false()" tunnel="yes"/>
<xsl:sequence select="$flag"/>
</xsl:template>

</xsl:stylesheet>

Although the template matching foo does not have an xslaram 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/
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      12-26-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
boolean flag vs threading.Event Daniel Python 2 02-28-2007 04:01 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments