[xsl-fo] : Does FO support reusable style definition, similar to CSS?

View: New views
4 Messages — Rating Filter:   Alert me  

[xsl-fo] : Does FO support reusable style definition, similar to CSS?

by solmyr72 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 
Newbie question, please:
Does FO support 'reusable formatting' definitions, similar to CSS "Class" ?
For example, suppose I have a document with 2 types of text:
- Heading, using font size 20pt
- Content, using font size 13pt

So , a naiive approach produces this page:
<fo:block font-size="20pt"> Some Heading  </fo:block>
<fo:block font-size="13pt"> Some content...  </fo:block>
<fo:block font-size="20pt"> More Heading  </fo:block>
<fo:block font-size="13pt"> More content...  </fo:block>


But this is difficult to maintain (e.g if I change my mind and want all headings to be 25pt).
Is there a better way ? Does FO support something like the 'Class' notion of CSS , so that you declare that 'MyHeading' means 'font size of 20', and from now on use it, something like:
 <fo:block class='MyHeading'>
 

Thanks very much !


Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV.

Re:

by Roland Neilands :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Sol,

If you're using XSLT to create your FO, then you can use attribute-sets
for this.

Regards,
Roland


sol myr wrote:

> Hi,
>  
> Newbie question, please:
> Does FO support 'reusable formatting' definitions, similar to CSS
> "Class" ?
> For example, suppose I have a document with 2 types of text:
> - Heading, using font size 20pt
> - Content, using font size 13pt
>
> So , a naiive approach produces this page:
> <fo:block font-size="20pt"> Some Heading  </fo:block>
> <fo:block font-size="13pt"> Some content...  </fo:block>
> <fo:block font-size="20pt"> More Heading  </fo:block>
> <fo:block font-size="13pt"> More content...  </fo:block>
>
>
> But this is difficult to maintain (e.g if I change my mind and
> want all headings to be 25pt).
> Is there a better way ? Does FO support something like the 'Class'
> notion of CSS , so that you declare that 'MyHeading' means 'font size
> of 20', and from now on use it, something like:
>  <fo:block class='MyHeading'>
>  
>
> Thanks very much !
>
> ------------------------------------------------------------------------
> Ready for the edge of your seat? Check out tonight's top picks
> <http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/> on Yahoo! TV.


Re: [xsl-fo] : Does FO support reusable style definition, similar to CSS?

by Mark Lundquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Hi Sol,

On Jul 4, 2007, at 12:45 PM, sol myr wrote:

> Newbie question, please:
> Does FO support 'reusable formatting' definitions, similar to CSS
> "Class" ?
> For example, suppose I have a document with 2 types of text:
> - Heading, using font size 20pt
> - Content, using font size 13pt
>
> So , a naiive approach produces this page:
> <fo:block font-size="20pt"> Some Heading  </fo:block>
> <fo:block font-size="13pt"> Some content...  </fo:block>
> <fo:block font-size="20pt"> More Heading  </fo:block>
> <fo:block font-size="13pt"> More content...  </fo:block>
>
>
> But this is difficult to maintain (e.g if I change  my mind and
> want all headings to be 25pt).
> Is there a better way ? Does FO support something like the 'Class'
> notion of CSS , so that you declare that 'MyHeading' means 'font size
> of 20', and from now on use it, something like:
>  <fo:block class='MyHeading'>

You need to shift your thinking :-)

HTML is a document language.  XSL-FO is not.  It's a layout language,
which is something completely different.  You're not meant to write
documents in XSL-FO.  The idea with XSL is that you are supposed to use
XSLT and XSL-FO together.  So instead of necessarily using a predefined
document language like HTML, you write your document in whatever XML
vocabulary suits your task, and then use XSLT transforms to translate
that into XSL-FO, which is an XML layout language.  In XSL-FO there is
no "formatting properties language" like CSS (with hooks in the
document language to trigger the properties... like "class" and "id"
attributes), because there's no need for one in the way XSLT-FO is
meant to be used.

So to take up your example, the source document might contain markup
like this:

        <heading>blah blah blah... </heading>
        <content>blah blah blah... </content>

        <heading>blah blah blah... </heading>
        <content>blah blah blah... </content>

...which is very easy to maintain.  Your XSLT stylesheet might contain:

        <xsl:template match="heading">
                <fo:block font-size="20pt">
                        <xsl:apply-templates/>
                </fo:block>
        </xsl:template>

        <xsl:template match="content">
                <fo:block font-size="13pt">
                        <xsl:apply-templates/>
                </fo:block>
        </xsl:template>

...which is also very easy to maintain.

Running the source document through the XSLT stylesheet produces the
XSL-FO source like in your example, which you quite rightly do not have
to maintain by hand!

cheers,
—ml—



Re: [xsl-fo] : Does FO support reusable style definition, similar to CSS?

by Alexandre Moraes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HI, I found in another site an answer for this.

You can use attribut sets like this.

Here's a direct quote from http://www.w3.org/TR/xslt.html#attribute-sets
>
> The following example creates a named attribute set title-style and uses
it
> in a template rule.
>
> <xsl:template match="chapter/heading">
>   <fo:block quadding="start" xsl:use-attribute-sets="title-style">
>     <xsl:apply-templates/>
>   </fo:block>
> </xsl:template>
>
> <xsl:attribute-set name="title-style">
>   <xsl:attribute name="font-size">12pt</xsl:attribute>
>   <xsl:attribute name="font-weight">bold</xsl:attribute>
> </xsl:attribute-set>
>

Alexandre


solmyr72 wrote:
Hi,       Newbie question, please:   Does FO support 'reusable formatting' definitions, similar to CSS "Class" ? For example, suppose I have a document with 2 types of text: - Heading, using font size 20pt - Content, using font size 13pt So , a naiive approach produces this page: <fo:block font-size=<?XML:NAMESPACE PREFIX = FO />"20pt"> Some Heading  </fo:block> <fo:block font-size="13pt"> Some content...  </fo:block> <fo:block font-size="20pt"> More Heading  </fo:block> <fo:block font-size="13pt"> More content...  </fo:block> But this is difficult to maintain (e.g if I change
 my mind and want all headings to be 25pt).   Is there a better way ? Does FO support something like the 'Class' notion of CSS , so that you declare that 'MyHeading' means 'font size of 20', and from now on use it, something like:    <fo:block class='MyHeading'>       Thanks very much !
      Ready for the edge of your seat?
Check out tonight's top picks  on Yahoo! TV.