[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Dynamically determining line wraps in HTML table cell
I have a problem that I am not sure how to tackle. I need to transform long sentences into multiple HTML tables for inclusion into a Microsoft Word document. With short sentences I have no issues, and the HTML tables are formatted for inclusion in Word without any problems. But with longer sentences, I have to divvy up the sentence into fragments. The issue for me is figuring out how to know when to divide a longer text sentence into multiple tables so each table fits width-wise in the Word document. Are there ways to calculate width using XSL other than just string length? The reason I am creating separate tables is because each of these will ultimately be interlinearized with morphemes and glosses underneath. Refer to Leipzig glossing rules (https://www.eva.mpg.de/lingua/pdf/Glossing-Rules.pdf). The problem is actually much more complex as the glosses in subsequent rows may be longer than the words themselves, and the glosses align with the start of each word, but I thought I would start with this initial problem and see what ideas folks might recommend. I was also wondering if this is the kind of thing that XSL-FO might be useful for. I have very limited familiarity with XSL-FO. I suspect that my easiest course of action is to: a. pre-determine the left and right margins, indents, etc. for the Word document and define a style for the example sentences. b. determine the maximum width of a line based on above. c. determine the number of m characters (m being the max width character possible) at a specified font-size that can fit within that width in (b) d. use the number in (c) in the XSLT to ensure that sentence fragments are always shorter than this number of characters. The above strategy will work most of the time for roman-based orthographies but I suspect will be an issue for other non-Roman orthographies. So, another thought: I suppose one could call an external function fDetermineWrappedText(cell_width, font, font-size, string) that would populate a table cell and then determine the portion that wraps, then return that fragment back to the XSLT. The XSLT could then put that returned fragment into its own table. I found some suggestions on how to find the line wraps here: https://stackoverflow.com/questions/3738490/finding-line-wraps. I have minimal experience using external functions in XSLT but I think this strategy may be more helpful in the long run. Simplified source example: <document> <sentence>John went to the store.</sentence> <sentence>Lorem ipsum dolor sit amet, ac et et inceptos eget sollicitudin, in urna velit et consectetuer eget cras, dictum erat turpis sed velit donec blandit, integer volutpat at dictum nullam nunc.</sentence> </document> XSLT process. Output example: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <table> <tr><td>John went to the store.</td></tr> </table> <hr/> <table> <tr><td>Lorem ipsum dolor sit amet, ac et et inceptos eget </td></tr> </table> <table> <tr><td>sollicitudin, in urna velit et consectetuer eget cras,</td></tr> </table> <table> <tr><td>dictum erat turpis sed velit donec blandit, integer</td></tr> </table> <table> <tr><td>volutpat at dictum nullam nunc.</td></tr> </table> <hr/> </body> </html> Any suggestions in the overall approach to the problem and what you would do if using XSLT? Thanks! Larry
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|