473,397 Members | 1,969 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,397 software developers and data experts.

the varable thing...

R
Hello everybody.

I hava a trouble with variables.

Value of my variable depends on count() if count() returns a number
less then 2
my variable ($width) use default value: 2

here is my XSLT code:

<xsl:choose>
<xsl:when test="count(../group[@style='inline']/*) > 2">
<xsl:variable name="width">
<xsl:value-of select="count(../group[@style='inline']/*)"/>
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="width">2</xsl:variable>
</xsl:otherwise>
</xsl:choose>

and later on:

<tr>
<th colspan="{$width}">....

and when my PHP5 DOM Parser reaches this moment i receive error:

Warning: runtime error: file
/home/xh/workspace/ERS_new/stylesheets/utils/xform.xsl element th in
Warning: unregistered variable width in

if I replace $width with count(...) everything is OK - but I need a
variable
to handle it when for example count() < 2

and by the way - one more question

count(../group[@style='inline']/*) returns number of children of all
group
elements with attribute style.
How can I select ony the maximal count of children of groups elements?

thanks in advance for any help
best regards
R
Jul 20 '05 #1
2 1200


R wrote:

I hava a trouble with variables.

Value of my variable depends on count() if count() returns a number
less then 2
my variable ($width) use default value: 2

here is my XSLT code:

<xsl:choose>
<xsl:when test="count(../group[@style='inline']/*) > 2">
<xsl:variable name="width">
<xsl:value-of select="count(../group[@style='inline']/*)"/>
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="width">2</xsl:variable>
</xsl:otherwise>
</xsl:choose>


Those variables are then only known in the scope of the parent element,
meaning not in any way "later on".
So you probably need
<xsl:variable name="width">
<xsl:choose>
...
</xsl:choose>
<xsl:otherwise>...</xsl:otherwise>
</xls:variable>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
ru******@poczta.onet.pl (R) writes:
Hello everybody.

I hava a trouble with variables.

The scope of a variable binding is the element in which the binding
appears so her:

<xsl:choose>
<xsl:when test="count(../group[@style='inline']/*) > 2">
<xsl:variable name="width">
<xsl:value-of select="count(../group[@style='inline']/*)"/>
</xsl:variable>
</xsl:when>
The scope is the xsl:when and it's gone out of scope as soon as it's defined.
<xsl:otherwise>
<xsl:variable name="width">2</xsl:variable>
</xsl:otherwise>
</xsl:choose>


You should make your code match the english description of what you
wanted to do: you didn't want to only conditionally declare a variable
depending on whether some condition was true, you want to
unconditionally declare the variable, with a value that depends on some
condition, so place the condition in the content of the variable binding:

<xsl:variable name="width">
<xsl:choose>
<xsl:when test="count(../group[@style='inline']/*) > 2">
<xsl:value-of select="count(../group[@style='inline']/*)"/>

</xsl:when>
<xsl:otherwise>2</xsl:otherwise>
</xsl:choose>
</xsl:variable>

Actually for the test you don't need to count them all and then compare
that against 2, you just want to know if there is a third node, so

<xsl:when test="(../group[@style='inline']/*)[3]">

(most uses of count() in a test can be replaced in the same way)

In this case I think your value is in fact 2 + the number of nodes in
the source (not counting the first 2, if they exist) in which case you
can define that directly as
<xsl:variable name="width" select="2 + count((../group[@style='inline']/*)[position()&gt;2])">"/>

David
Jul 20 '05 #3

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

Similar topics

3
by: Ron_Adam | last post by:
Hi, Sometimes it just helps to see what's going on, so I've been trying to write a tool to examine what names are pointing to what objects in the current scope. This still has some glitches,...
2
by: Graham Mattingley | last post by:
How to I test a varable to see if it contains a number and not a text value ?? I want to use this to detect if people have edited my get strings in the URL field of the browser, before it gets...
1
by: Gary | last post by:
Open the web browser at the same time, the session varable in the second broswer is disappeared. All The Session Varable is declared in the webform page load.
2
by: Suresh Kumar Rathod | last post by:
HI friends... Can any body give reason / logic behind static varable lifetime through out the process execution. i.e how does compiler maintains the static varable life through out the process...
3
by: Tony Lance | last post by:
Big Bertha Thing spider Cosmic Ray Series Possible Real World System Constructs http://web.onetel.com/~tonylance/spider.html Access page JPG 11K Image Astrophysics net ring Access site...
0
by: Tony Lance | last post by:
Big Bertha Thing progress Cosmic Ray Series Possible Real World System Constructs http://web.onetel.com/~tonylance/progress.html Access page to 6K Web page Astrophysics net ring access site...
0
by: Tony Lance | last post by:
Big Bertha Thing lightcraft Cosmic Ray Series Possible Real World System Constructs http://web.onetel.com/~tonylance/liteship.html 14K Web page Astrophysics net ring Access site Newsgroup...
0
by: forgedascendant | last post by:
Hello All, I am kinda new to VBA interacting with excel...or just VBA for that matter. I was wondering if there was a was to determine if a ranged varable (lets say ProductXRange) is empty? ...
1
by: Eric Hanchrow | last post by:
(This is with Python 2.5.2, on Ubuntu Hardy, if it matters.) This seems so basic that I'm surprised that I didn't find anything about it in the FAQ. (Yes, I am fairly new to Python.) Here are...
3
by: J. Cliff Dyer | last post by:
On Thu, 2008-05-08 at 12:00 -0700, Eric Hanchrow wrote: It's the same reason as this: 5 5 6 5 Python "variables" are just names that point at objects. When you
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: 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
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:
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...
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.