Dynamic Formatting Again
By Tim Dexter-Oracle on Jul 10, 2007
Question on the forum today asking how you might use some meta information stored in the incomng XML data to format the final output i.e. override any formatting you might have created in the RTF template. I covered how to do this if the XML is actually HTML e.g.
You can check that out here.
What to do if you have something like the following:
<TITLE format="bold">The Crazy Dog</TITLE>
<TEXT format="italic">I've seen many strange dogs but this is the one. you should see some of the things hes done. I've seen him jump and try to eat sand. he had a mouth full of dirt as soon as he would land. if you saw him you'd probably giggle. if you do you have probably seen him squiggle. the strange thing is hes never snappy but he is always happy! every one knows him now and he says to you "bow wow!" </TEXT> </POEM>
Notice the format attributes specifying how the text shuld be formatted.
We need to use some of the techniques from the HTML formatting article to specify the formatting required using the XSLFO syntax. Keeping things simple we can just use simple conditional 'if' statements to check the value of the 'format' attributes. Using the TITLE element we can use:
<?if:@format='bold'?> <xsl:attribute xdofo:ctx="block" name="font-weight">bold</xsl:attribute> <?end if?>
Similar approach for the italic or any other attribute. You could build a subtemplate to handle all of the possible 'formatting' options to simplify your coding and making it more dynamic. Get ya example files here.
In case you're wondering, the poem is from my son about our new puppy.