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

XSLT changing sibling attribute value


Hi,

I have an XSLT that needs to adjust height and width attributes
of images. It sets the width to a particular value and should
adjust the height correspondingly. I cannot seem to get it to
change the height value.

XSLT code snippet:

<xsl:param name="maxwidth">220</xsl:param>

<xsl:template match="@width">
<xsl:choose>
<xsl:when test="parent::img">
<xsl:attribute name="width"><xsl:value-of
select="$maxwidth"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of
select="round(number(../@height) * ($maxwidth div
number(.)))"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
when working on:

<img width="400" height="100"/>

the result is:

<img width="220" height="100"/>

The height does not change. I cannot seem to alter the height
value when I am at the width attribute node.

How do I do that?

Thanx

Clara

Oct 26 '05 #1
2 1419
cl***@hotmail.com wrote:

Hi,

I have an XSLT that needs to adjust height and width attributes
of images. It sets the width to a particular value and should
adjust the height correspondingly. I cannot seem to get it to
change the height value.

XSLT code snippet:

<xsl:param name="maxwidth">220</xsl:param>

<xsl:template match="@width">
<xsl:choose>
<xsl:when test="parent::img">
<xsl:attribute name="width"><xsl:value-of
select="$maxwidth"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of
select="round(number(../@height) * ($maxwidth div
number(.)))"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
when working on:

<img width="400" height="100"/>

the result is:

<img width="220" height="100"/>

The height does not change. I cannot seem to alter the height
value when I am at the width attribute node.

How do I do that?


Works fine here using Saxon-8 under jdk1.5.0_04 (FC4)

<img width="220" height="55">

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Oct 26 '05 #2
Weird, it seems to depend on XSLT engine then.

I have editix and tried a perl script using XML::LibXML and
XML::LibXSLT, both do not change the height attribute. If I do

<xsl:attribute name="foobar"><xsl:value-of
select="round(number(../@height) * ($maxwidth div
number(.)))"/></xsl:attribute>

the foobar attribute is added with the correct value. Changing
the existing height does not work. Is there a workaround?

Clara

Oct 27 '05 #3

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

Similar topics

4
by: Richard Rudie | last post by:
Have any other Windows iTunes users looked at the XML file iTunes uses as its database? (Does iTunes for Mac use an XML file, too?) When I noticed that it was XML, I thought it might be useful, or...
1
by: Ralph Snart | last post by:
i'm trying to do the classic alternating table row colors trick. i can't use position() mod 2 in this case because sometimes the template is called but it decides not to print the particular...
1
by: Oleg Konovalov | last post by:
Hi, I am new to XSLT, trying to significantly modify somebody else's XSL. That is not 2.0. I need to create min & max variable(s) to be used in many templates and sub-templates based on...
4
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform that value to an attribute in the XML output...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: 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
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...

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.