Ecrion Software Inc. Homepage
Forum Home Forum Home > XF Rendering Server > XSL-FO
  New Posts New Posts RSS Feed: xsl fo style from xml
  FAQ FAQ  Forum Search   Register Register  Login Login

xsl fo style from xml

 Post Reply Post Reply
Author
Message / View First Unread Post
jaisudha View Drop Down
Newbie
Newbie


Joined: 29 Aug 2011
Posts: 1
Post Options Post Options   Quote jaisudha Quote  Post ReplyReply Direct Link To This Post Topic: xsl fo style from xml
    Posted: 29 Aug 2011 at 9:05am
Hi,

My xml attribute holds this value
style = color:red;background-color:red;
now i have modified and got in an xsl variable as
$style which holds color="red" background-color="red"
now i have to place this xsl variable near fo:inline
that is <fo:inline $style>
so that it should be rendered as <fo:inline color="red" background-color="red">
how can i place the xsl variable $style inisde fo:inline tag
Any suggesstions. Thanks in Advance.
Back to Top
radup View Drop Down
Admin Group
Admin Group
Avatar
Adminstrator

Joined: 19 May 2008
Posts: 83
Post Options Post Options   Quote radup Quote  Post ReplyReply Direct Link To This Post Posted: 29 Aug 2011 at 12:24pm
In your case, you can use xsl:attribute. Check the following link for more information about this xsl element: http://www.w3schools.com/xsl/el_attribute.asp

First you need to write an xsl:template that splits and applies these style attributes from your xml.
The template should look something like this:
<xsl:template name="ApplyStyle">
    <xsl:param name="style" select="''"/>

    <xsl:if test="normalize-space($style)">
        <xsl:variable name="part1">
            <xsl:choose>
                <xsl:when test="contains($style, ';')">
                    <xsl:value-of select="substring-before(normalize-space($style), ';')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="normalize-space($style)"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="part2" select="substring-after(normalize-space($style), ';')"/>
        
        <!-- apply attribute style -->
        <xsl:if test="$part1 and contains($part1, ':')">
            <xsl:variable name="name" select="substring-before($part1, ':')"/>
            <xsl:variable name="value" select="substring-after($part1, ':')"/>

            <xsl:attribute name="{$name}"><xsl:value-of select="$value"/></xsl:attribute>
        </xsl:if>

        <!-- apply remaining attributes -->
        <xsl:if test="$part2">
            <xsl:call-template name="ApplyStyle">
                 <xsl:with-param name="style" select="$part2"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:if>
</xsl:template>

After writing it, you need to call this template in your fo:inline element and looks like this:
<fo:inline>
    <xsl:call-template name="ApplyStyle">
        <xsl:with-param name="style" select="$style"/>
    </xsl:call-template>
    Your content here ...
</fo:inline>

Note: The call template must be the first child of the fo:inline element.





Edited by radup - 29 Aug 2011 at 12:30pm
I'm happy when my mind is free and my senses are occupied.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz

This page was generated in 0.063 seconds.