XSLT changing sibling attribute value

Discussion in 'XML' started by clres@hotmail.com, Oct 26, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. Peter Flynn Guest

    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/
    Peter Flynn, Oct 27, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page