473,554 Members | 2,197 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 3800
> <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
1453
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
1284
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
1412
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
1078
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
1584
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">...
2
1278
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...
0
1016
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
1352
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...
1
1186
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
1229
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,...
0
7535
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...
0
8051
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...
1
7574
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...
0
7894
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...
0
6161
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...
1
5442
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...
0
3579
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...
1
2026
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
0
850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.