473,765 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT: xsl:variable : help!

The following code does not work:

<xsl:variable name="width" select="form:im age-width"/>
<xsl:if test="$width>$m ax_image_width" >
<xsl:variable name="width" select="$max_im age_width"/>
</xsl:if>
<img class="admin" width="{$width} " src="{form:imag e-url}" />

The width attribute of img is always "", the $max_image_widt h variable is set to 200
and $width is initially set to the width of the image.

The purpose of this code is to bound the image width in an html page to a maximum length.
But the code does not work.

Please help!

Pseudo-code of the xsl code:

$max_image_widt h=200;
$width=[some value selected from xml file]

if($width>$max_ image_width) {
$width=$max_ima ge_width
}

print $width;

Jul 20 '05 #1
10 3826
> <xsl:variable name="width" select="form:im age-width"/>
<xsl:if test="$width>$m ax_image_width" >
<xsl:variable name="width" select="$max_im age_width"/>
</xsl:if>
<img class="admin" width="{$width} " src="{form:imag e-url}" />

A variable cannot be declared twice in the same scope in XSLT.
And the 'xsl:if' and 'xsl:variable' nodes must be inversed:

<xsl:variable name="width">
<xsl:if test="form:imag e-width &gt; $max_image_widt h">
<xsl:value-of select="$max_im age_width"/>
</xsl:if>
<xsl:if test="form:imag e-width &lt;= $max_image_widt h">
<xsl:value-of select="form:im age-width"/>
</xsl:if>
</xsl:variable>
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Joris Gillis wrote:
<xsl:variable name="width" select="form:im age-width"/>
<xsl:if test="$width>$m ax_image_width" >
<xsl:variable name="width" select="$max_im age_width"/>
</xsl:if>
<img class="admin" width="{$width} " src="{form:imag e-url}" />

A variable cannot be declared twice in the same scope in XSLT.
And the 'xsl:if' and 'xsl:variable' nodes must be inversed:

<xsl:variable name="width">
<xsl:if test="form:imag e-width &gt; $max_image_widt h">
<xsl:value-of select="$max_im age_width"/>
</xsl:if>
<xsl:if test="form:imag e-width &lt;= $max_image_widt h">
<xsl:value-of select="form:im age-width"/>
</xsl:if>
</xsl:variable>


Ok ive this:

<xsl:variable name="width">
<xsl:choose>
<xsl:when test="form:imag e-width &gt; $max_image_widt h">
<xsl:value-of select="$max_im age_width"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="form:im age-width"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<img class="admin" width="{$width} " src="{form:imag e-url}" />
But is does not work, the width atribute stays empty, so $width is not assigned a value.

Can't is use > in place of &gt; ??? and for &lt; is < not a possibility?

I think the parser can see whether > is part of markup or an expression
Jul 20 '05 #3
Tjerk Wolterink wrote:
Joris Gillis wrote:
<xsl:variable name="width" select="form:im age-width"/>
<xsl:if test="$width>$m ax_image_width" >
<xsl:variable name="width" select="$max_im age_width"/>
</xsl:if>
<img class="admin" width="{$width} " src="{form:imag e-url}" />

A variable cannot be declared twice in the same scope in XSLT.
And the 'xsl:if' and 'xsl:variable' nodes must be inversed:

<xsl:variable name="width">
<xsl:if test="form:imag e-width &gt; $max_image_widt h">
<xsl:value-of select="$max_im age_width"/>
</xsl:if>
<xsl:if test="form:imag e-width &lt;= $max_image_widt h">
<xsl:value-of select="form:im age-width"/>
</xsl:if>
</xsl:variable>


Ok ive this:

<xsl:variable name="width">
<xsl:choose>
<xsl:when test="form:imag e-width &gt; $max_image_widt h">
<xsl:value-of select="$max_im age_width"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="form:im age-width"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<img class="admin" width="{$width} " src="{form:imag e-url}" />
But is does not work, the width atribute stays empty, so $width is not
assigned a value.

Can't is use > in place of &gt; ??? and for &lt; is < not a possibility?

I think the parser can see whether > is part of markup or an expression

Wait: it did work, the element form:image-width was nameed form:width , so stupid fault.
Jul 20 '05 #4
> Can't is use > in place of &gt; ??? and for &lt; is < not a possibility?

According to the XPath 1.0 recommandation:

<cite>
XPath expressions often occur in XML attributes. The grammar specified in this section applies to the attribute value after XML 1.0 normalization. So, for example, if the grammar uses the character <, this must not appear in the XML source as < but must be quoted according to XML 1.0 rules by, for example, entering it as &lt;
</cite>

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #5
On Wed, 24 Nov 2004 18:11:54 GMT, "Joris Gillis" <ro**@pandora.b e>
wrote:
Can't is use > in place of &gt; ??? and for &lt; is < not a possibility?


According to the XPath 1.0 recommandation:

<cite>
XPath expressions often occur in XML attributes. The grammar specified in this section applies to the attribute value after XML 1.0 normalization. So, for example, if the grammar uses the character <, this must not appear in the XML source as < but must be quoted according to XML 1.0 rules by, for example, entering it as &lt;
</cite>


On the other hand, there's no technical reason to use &gt; instead of >.
Some people like to use &gt; for symmetry with <, or so they don't have
to remember which one needs to be escaped.

Personally, for readability I prefer to turn the expression around to
avoid escaping, e.g.

<xsl:if test="$x >= $y"> instead of <xsl:if test="$y &lt; $x">
--
Morris M. Keesan -- ke****@alum.bu. edu

Jul 20 '05 #6
Morris M. Keesan wrote:
On Wed, 24 Nov 2004 18:11:54 GMT, "Joris Gillis" <ro**@pandora.b e>
wrote:
Can't is use > in place of &gt; ??? and for &lt; is < not a possibility?


According to the XPath 1.0 recommandation:

<cite>
XPath expressions often occur in XML attributes. The grammar specified in this section applies to the attribute value after XML 1.0 normalization. So, for example, if the grammar uses the character <, this must not appear in the XML source as < but must be quoted according to XML 1.0 rules by, for example, entering it as &lt;
</cite>

On the other hand, there's no technical reason to use &gt; instead of >.
Some people like to use &gt; for symmetry with <, or so they don't have
to remember which one needs to be escaped.

Personally, for readability I prefer to turn the expression around to
avoid escaping, e.g.

<xsl:if test="$x >= $y"> instead of <xsl:if test="$y &lt; $x">


But do all xml parses and xslt processor work with both &gt; and > ?
I mean: is it valid to use > in stead of &gt;
Jul 20 '05 #7
In article <co**********@n etlx020.civ.utw ente.nl>,
Tjerk Wolterink <tj***@wolterin kwebdesign.com> wrote:
But do all xml parses and xslt processor work with both &gt; and > ?
I mean: is it valid to use > in stead of &gt;


Yes, in the context of attribute values there is no difference between
the two.

The only case where there is a difference is when the > could terminate
a CDATA section: ]]> is different from ]]&gt; (and ]]> is disallowed in
content when it doesn't end a CDATA section).

-- Richard
Jul 20 '05 #8
On 25 Nov 2004 22:19:19 GMT, ri*****@cogsci. ed.ac.uk (Richard Tobin)
wrote:
In article <co**********@n etlx020.civ.utw ente.nl>,
Tjerk Wolterink <tj***@wolterin kwebdesign.com> wrote:
But do all xml parses and xslt processor work with both &gt; and > ?
I mean: is it valid to use > in stead of &gt;


Yes, in the context of attribute values there is no difference between
the two.

The only case where there is a difference is when the > could terminate
a CDATA section: ]]> is different from ]]&gt; (and ]]> is disallowed in
content when it doesn't end a CDATA section).


But, just to be clear, in a CDATA section, &gt; is 4 characters, not
one, and if you have the character sequence "]]>", you can't represent
it in a CDATA section. You'd have to end the CDATA, and put part of
that sequence in plain parsed character data, or in an adjacent CDATA.
--
Morris M. Keesan -- ke****@alum.bu. edu

Jul 20 '05 #9
In article <mh************ *************** *****@4ax.com>,
Morris M. Keesan <ke****@alum.bu .edu> wrote:
But, just to be clear, in a CDATA section, &gt; is 4 characters, not
one, and if you have the character sequence "]]>", you can't represent
it in a CDATA section. You'd have to end the CDATA, and put part of
that sequence in plain parsed character data, or in an adjacent CDATA.


Sorry, I was unclear and incomplete. Yes, you have to do something if
you want the sequence ]]> in a CDATA section. But you *also* have to
do something if you want the sequence ]]> *not* in a CDATA section:
it's not allowed to occur in ordinary content. This is not
well-formed:

<foo>]]></foo>

So if you're serializing text, you have to either keep track of
characters to ensure that you don't output ]]>, or (more simply)
just use &gt; all the time.

-- Richard
Jul 20 '05 #10

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

Similar topics

1
1460
by: timothy ma and constance lee | last post by:
Sir I am using the recursive template to generate the dynamic drop down list as below: <xsl:template name="generateDropdown"> <xsl:param name="length" /> <xsl:param name="refrid" /> <xsl:param name="count" select="$length"/>
4
1293
by: Gerald Aichholzer | last post by:
Hello NG, I have a XML file looking like: <!-- some elements here --> <plugin> <icon></icon> <!-- some elements here --> <object> <!-- some elements here -->
8
1420
by: Gerald Aichholzer | last post by:
Hello NG, I try to apply the following template <xsl:template match="objectgroup"> <xsl:copy> <xsl:apply-templates select="*|@*"/> <xsl:variable name="object" select="."/> <xsl:for-each select="//plugins/plugin"> <plugin pid="{./@pid}"
2
1085
by: Ralph Snart | last post by:
I have a bunch of nodes called <product>. Some of them will have <gumball_id> child elements. How can I get the first 4 products that have gumball_ids ? The previous programmer wrote: select="product" But that only looks at the first 4 <product>s. It doesn't find the first 4 with a specific child.
5
1603
by: Patrick.O.Ige | last post by:
I have an xml and i'm trying to loop each node... When i do FOR EACH i seem not to get my desired result I want to loop through and get only the values that matches the question i specified with the corresponding answers? I don't want to retrieve all the Answer and VoteAnswers nodes <xsl:for-each select="NSurveyVoter/Voter/Question/Answer"> <xsl:value-of select="Answer/Answer/text()"/>
2
1286
by: CK | last post by:
Hi Everyone, I have a custom web part in SharePoint. I want a cell in the table to be conditionally formatted. Using Front Page it's fairly easy to make general formatting chnages, like color, italics, and bold, etc... My problem is that I want to show an image in a cell. The image will be based on the content in another cell. If the value of the cell is "Complete" I want to show image A, if "In Progress" image B, and if "Other" then...
0
1024
by: poli | last post by:
Hi, It is my first xslt document that I have to write. And I have to do it quick (1 day). PLease help me. I have this input xml file: <?xml version="1.0" encoding="UTF-8"?> <Node version="1.1.0.0"> <Model Name="x"> <OutputResolution ResX="600" ResY="600">
1
1359
by: Paulson | last post by:
Hi guys I got a problem.I am using xml/xsl in asp.net. I know how to add update delete nodes in xml Files. But I dont know how to create a good stylesheet for it.I have read xsl in w3schools and done little but it does not help the look of the xml/xsl. Can anyone tell me from where I can learn how to design god stylesheets using xslt(xsl)? I need to navigate on same page and get various...
1
1198
by: tkahn6 | last post by:
Hi! Ok so im having a very very rookie (i assume) problem. I want to take this: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="xslTest.xsl"?> <dataTree> <group>
4
1237
by: a1suria | last post by:
Hi, there.. could you please show me some examples of XSLT codes to match XSD with XML .. the stylesheet should output Yes if matches the schema and No if doesn't match.. schema contains empty Complex type, sequence, choice and elements (no elements type/ attribute/ strings and no text in xml) we can include if statements, recursions, choices and apply templets in stylesheet but HOwww.. pleeeeeeeeeeese help
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
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
8831
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...
1
7378
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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

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.