XSLT changing sibling attribute value

C

clres

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
 
P

Peter Flynn

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
 
M

mvanderbijl

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top