Re: [xsl] How to 'execute' a table without manually converting it to a bunch of nested if-then-else statements?

Subject: Re: [xsl] How to 'execute' a table without manually converting it to a bunch of nested if-then-else statements?
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Feb 2023 02:03:20 -0000
On Sun, 2023-02-19 at 18:21 +0000, Roger L Costello costello@xxxxxxxxx
Alas, as you
> know, Microsoft Word tables cannot be embedded into XSLT programs.

Well, since these days they are encoded in XML in the Word files, they
actually can.

In practice nested maps or an xsl:choose or an element structure or
functions or named templates or a combination, whatever seems to fit in
best with the rest of the stylesheet probably.


> I remember Liam saying (paraphrasing): "Any program longer than 6
> lines has bugs."

I think i said that i had never seen a program longer than 6 lines that
didn't have a bug.

>  How do *you* translate tables into code? Do you have a way that is
> 100% guaranteed to faithfully/accurately encode the table?

For a large decision table, i'd indeed want some static representation
of it. The XPath fragments in your example suggest the use of maps
(which preserve node identity), or possibly a map with a function for
each row, so that the XPath expressions are contained in the body of
the function and evaluated on demand.

One way might look like this:

<xsl:variable name="WidthPrecisionTable" as="map(*)"
  select="
    map {
      '* *' : function($arg as node()) as item()* {
        $arg/following-sibling::argument[2]
      },
      '* nonps' : function($arg as node()) as item()* {
        $arg/following-sibling::argument[1]
      }
 . . .
    }
  "/>

liam

--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org

Current Thread