[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can i assign value to a variable and used it in d

Subject: Re: Can i assign value to a variable and used it in different template
From: "Anton Triest" <anton@xxxxxxxx>
Date: Tue, 21 Sep 2004 09:59:34 +0200
xsl variable name
> <xsl:template name="process-style"> 
> <xsl:if test="normalize-space($name)='border' and self::table">
> <xsl:variable name="bordervalue" select='"$value"'/>
> </xsl:if> 
> </xsl:template>

That won't work because a variable's scope is its parent (xsl:if, in this case)
so if you want it to be available in other templates it must be a global variable.
But then, its value will be fixed throughout the stylesheet, so probably that's
not what you want in this case. Always remember, in XSLT you cannot change
the value of a variable once it has been declared...

What you can do, is declaring local $bordervalue variables inside the templates
where you call the "process-style" template, then you can use the value inside
that template and/or pass it on to other templates as a param:

    <xsl:template match="table">
        <xsl:variable name="bordervalue">
            <xsl:apply-templates select="@style" mode="get-border"/>
        <xsl:if test="number($bordervalue) &gt; 0">
            <xsl:call-template name="add-border-attributes">
                <xsl:with-param name="value" select="$bordervalue"/>
    <xsl:template match="@style" mode="get-border">
        ... get border value from style attribute ...

Maybe you can even combine processing the style and adding the
attributes into one template:

    <xsl:template match="table">
        <xsl:apply-templates select="@style" mode="add-border-attributes"/>
    <xsl:template match="@style" mode="add-border-attributes">
        <xsl:variable name="bordervalue">
            ... get border value ...
        <xsl:if test="number($bordervalue) &gt; 0">
            <xsl:attribute name="border-style">solid</xsl:attribute>
            ... add attributes ...

Good luck,

> Actually i am used this template for processing inline style.(above is a
> part of that).
> name variable contains the attribute name present in style attribute.My aim
> is to
> check whether the name is border,then i store it value to some variable.I
> want to use 
> this variable in  some other templates.
> <xsl:template name="tablechildborder">
> <xsl:if test="number($bordervalue) &gt; 0 "> 
> <xsl:attribute name="border-style">solid</xsl:attribute>
> <xsl:attribute name="border-separation">1pt</xsl:attribute>
> <xsl:attribute name="border-left-width">thin</xsl:attribute>
> <xsl:attribute
> name="border-right-width">thin</xsl:attribute>
> <xsl:attribute name="border-width">thin</xsl:attribute>
> </xsl:if>
> </xsl:template>
> <xsl:template name="tableborder">
> <xsl:when test="number($bordervalue) &gt; 0 ">
> <xsl:attribute name="border">
> <xsl:call-template name="createborder">
> <xsl:with-param name="tborder"
> select="$bordervalue"/>
> </xsl:call-template>
> </xsl:attribute>
> </xsl:when>
> </xsl:template>
> I tried this one.But i could not get the $bordervalue inside tableborder and
> tablechildborder template.First time it shown some error.Then i make the
> variable bordervalue
> as global.
> <xsl:stylesheet 
>   version="1.0" 
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:fo="http://www.w3.org/1999/XSL/Format"
>   xmlns:fox="http://xml.apache.org/fop/extensions">
> <!-- ==============================================
> Global variable declaration
> ==================================================-->
> <xsl:variable name="bordervalue"/>
> // All my template present here
> </xsl:stylesheet>
> How can i solve this problem?Can i assign a value to variable and use it in
> other template.
> Please help me.
> Thanks in advance
> George

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.