W3C home > Mailing lists > Public > www-xsl-fo@w3.org > May 2006

RE: How to reuse template code

From: Jordan Soet <jordan.soet@u21global.edu.sg>
Date: Wed, 17 May 2006 09:09:47 +0800
Message-ID: <3EC5CE64D03BFD4F976C7097C2F9FDFD49F635@sgmsexchg2.u21globalnet.com>
To: "omegared" <Shamem.Miah@scisys.co.uk>, <www-xsl-fo@w3.org>

Hi, for your first question, I think what you might want to do is look
at attribute sets. 

They're made by doing the following:

<xsl:attribute-set name="normal-block">
	<xsl:attribute name="font-family">Verdana</xsl:attribute>
	<xsl:attribute name="font-size">10pt</xsl:attribute>
	<xsl:attribute name="space-before">7pt</xsl:attribute>
	<xsl:attribute name="space-after">3pt</xsl:attribute>
	<xsl:attribute name="text-align">start</xsl:attribute>
	<xsl:attribute name="white-space-collapse">true</xsl:attribute>
</xsl:attribute-set>


And then used like this:

<xsl:element 
		name="fo:block" 
		use-attribute-sets="heading-block">
	<xsl:apply-templates/>
</xsl:element>

And then after you have the use-attribute-sets part you can still add
your own attributes, and it's always the later attribute that's applied,
so you might want to do something along these lines:


<xsl:template match="para1|para2">
	<xsl:element 
			name="fo:block"
			use-attribute-sets="block-attributes">
		<xsl:if test="self::para2"> 
			<xsl:attribute
name="text-indent>0.5in</xsl:attribute>
		</xsl:if>

		<xsl:apply-templates/>
	</xsl:element>
</xsl:template>

(note, I'm fairly new to xsl myself, so I'm not entirely sure that
works.)


With regards to your second question, I think what you're looking for
may be the call-template function? And then maybe you can pass in a
parameter for the node you want to process? As I said, I'm fairly new to
XSL too, so you'll have to look into this yourself, but hopefully it'll
at least point you in the right direction.


Hope that helps,
Jordan

-----Original Message-----
From: www-xsl-fo-request@w3.org [mailto:www-xsl-fo-request@w3.org] On
Behalf Of omegared (sent by Nabble.com)
Sent: Monday, May 15, 2006 7:40 PM
To: www-xsl-fo@w3.org
Subject: How to reuse template code



Hi

I am new to XSL-FO and was hoping somebody would be kind enough to
answer
the following questions.  I have read a number of online tutorials but
they
do not go above a very basic introduction.  I have been using xml and
xslt
files so as to separate my content and format. 

1)Suppose you have two paragraphs which have identical formatting e.g.
font
size, colour, style except that one paragraph begins with has different
alignment.  At the moment I am writing two templates e.g.

<xsl:template match="para1">
       <fo:block text-indent="0.5in" 
       		 font-size="12pt" 
                 font-family="sans-serif" 
                 line-height="15pt"
                 space-after.optimum="12pt"
                 text-align="right">
		<xsl:value-of select="."/>
	</fo:block>
</xsl:template>

and 

<xsl:template match="para2">
       <fo:block font-size="12pt" 
                 font-family="sans-serif" 
                 line-height="15pt"
                 space-after.optimum="12pt"
                 text-align="right">
		<xsl:value-of select="."/>
	</fo:block>
</xsl:template>

Is there no way of saying apply all of the template specification in
para1
to para2 but change the alignment with repeating the same styling
definitions?    Ddo I have to write separate templates every time
regardless?

2)If I want to apply exactly the same template, do I have to copy the
whole
template and change the XPath query?  Is there no way I can reuse the
same
template by sating something like:

<apply template select ="para"><value-of=/nodeA></apply template>
<apply template select ="para"><value-of=nodeJ></apply template>

--
View this message in context:
http://www.nabble.com/How-to-reuse-template-code-t1620380.html#a4390495
Sent from the w3.org - www-xsl-fo forum at Nabble.com.
Received on Wednesday, 17 May 2006 01:08:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:13 GMT