[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] How to 'execute' a table without manually converting i
Hi Folks, The UNIX shell has a printf command. Here's an example: printf "A string %s and a number %d" hello 10 The "..." part is called the format string. Following the format string are arguments. The %s indicates that the first argument (hello) is a string. The %d indicates that the second argument (10) is a number. %s is the most basic form. The complete form is: %[flag][width][.precision]s width can be either a number or *. If it is * then the width is specified by an argument, e.g., printf "A string %10s" hello <-- print hello in a field width of 10 printf "A string %*s" 15 hello <-- print hello in a field width of 15 Ditto for precision printf "A string %*.*s" 10 3 hello <-- 10 is the width, 3 is the precision, and the string to be printed is hello. Suppose the printf command is represented in XML and $arg is a variable that contains an argument. An XSLT program encounters %...s and must get the appropriate string from the arguments. If it is a simple %s then the string is in $arg. If it is %*s then the width is in $arg and the string is in $arg/following-sibling::argument[1]. If it is %*.*s then the width is in $arg, the precision is in $arg/following-sibling::argument[1], and the string is in $arg/following-sibling::argument[2]. Here's a table that describes where to get the string: width precision location of the string * * $arg/following-sibling::argument[2] * number or no precision specified $arg/following-sibling::argument[1] number or no width specified * $arg/following-sibling::argument[1] number or no width specified number or no precision specified $arg That, in my opinion, is a beautiful table. I wish that I could put that table into my XSLT program and instruct the XSLT processor, "Hey, use the table to get the appropriate string." Alas, as you know, Microsoft Word tables cannot be embedded into XSLT programs. Of course I can manually translate that table into a bunch of nested if-then-else expressions: if ($width eq '*') then if ($precision eq '*') then $arg/following-sibling::argument[2] else $arg/following-sibling::argument[1] else if ($precision eq '*') then $arg/following-sibling::argument[1] else $arg I suppose that translation is not too complicated. But in a larger table the likelihood of making mistakes in the translation grows exponentially. I remember Liam saying (paraphrasing): "Any program longer than 6 lines has bugs." Manually translating tables into code is fraught with peril. There must be a better way! By "better" I mean more assuredness that the code faithfully/accurately encodes the table. So, what I seek from you is this: How do *you* translate tables into code? Do you have a way that is 100% guaranteed to faithfully/accurately encode the table? /Roger
|
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
|