Hi Roger,
This can all be expressed as nested maps, and for the "else" part we need
to approve and in clude in XPath 4.0 my proposal for "Total Maps" :
https://github.com/qt4cg/qtspecs/issues/105
Thanks,
Dimitre
On Sun, Feb 19, 2023 at 10:20 AM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> Hi Folks,
>
> The UNIX shell has a printf command. Here's an example:
>
> printf "A string %s and a number %d" hello 10
>
> The "b&" 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, bHey, 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
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
|