Re: [xsl] Doing math in XSLT?

Subject: Re: [xsl] Doing math in XSLT?
From: "Michael Mueller-Hillebrand michael.mueller-hillebrand@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Apr 2024 06:18:21 -0000
Hi Dan,

Your assumption of column names being an indicator of column counts is the
real problem. I know of tools which e.g., between col1 and col2 insert
colname="col01", if the user clicks a button in the table editor interface to
insert an additional column. The CALS table spec at
https://www.oasis-open.org/specs/a502.htm says:

COLNAME: Column name of <entry>. Ignore if spanname or namest are present. It
is an error if colname is not defined in a <colspec> of the current context:
<tgroup>, <thead> or <tfoot>, or <entrytbl>.
Declared Value = NMTOKEN
Default = IMPLIED (column(s) determined by namest, spanname, or implicitly the
next.)

My advice would be to normalize the table before trying column arithmetic.
Since andrewwelch.com is gone, you may find a reliable source for his code
here: https://github.com/transpect/htmltables?tab=readme-ov-file

Michael MH


From: dvint dvint@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, April 1, 2024 9:59 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Doing math in XSLT?

I found at least one problem which is the substring-after. Not all of my
tables use col as a prefix but use just c. Not sure how that happens as these
are complex tables and I'm sure would have been created in the table editor.

Now exploring regex to just match the digits, but that looks like
analyze-string to do that. I'll have to research further to make sure there
are always digits in the name. May be safer to pull the value from the
collection definition. It looks like if there are no spans the colnum is not
added.



Sent from my Verizon, Samsung Galaxy smartphone


-------- Original message --------
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx<mailto:dnovatchev@xxxxxxxxx>"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>>
Date: 4/1/24 11:49 AM (GMT-08:00)
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [xsl] Doing math in XSLT?

Seems the problem is not in what you have described, but somewhere else.

I cannot reproduce it.

When this transformation:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";>
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="entry">
    <xsl:variable name="vStart" as="xs:double"
     select="number(substring-after(@namest, 'col'))"/>
     <xsl:value-of select="$vStart"/>
  </xsl:template>
</xsl:stylesheet>

is applied on the provided XML document:

<row>
   <entry nameend="col2" namest="col1">
     <p>OpenID Connect client settings</p>
     <note id="note_N1055C">The following parameters are only applicable
                        when this client supports the OpenID Connect use
                        cases.</note>
   </entry>
</row>

The wanted/expected/correct result is produced:

1

On Mon, Apr 1, 2024 at 11:36b/AM dvint@xxxxxxxxx<mailto:dvint@xxxxxxxxx>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>> wrote:
I have the following XML

<row>
        <entry nameend="col2" namest="col1">
                <p>OpenID Connect client settings</p>
                <note
                        id="note_N1055C"
                        >The following parameters are only applicable
                        when this client supports the OpenID Connect use
                        cases.</note>
        </entry>
</row>

The attributes nameend="col2" namest="col1" indicate that this row spans
2 columns (end - start + 1).

I've tried this to try and get the numbers 1 and 2 from these strings,
but I get NaN errors

<xsl:variable name="start"
        select="number(substring-after(@namest, 'col'))" as="xs:double"/>
<xsl:variable name="end"
        select="number(substring-after(@nameend, 'col'))" as="xs:double"/>

I've tried this in different combinations with/without the
as="xs:double" and number() and those variations throw the same error.

The table itself has this information

<table colsep="0" frame="none" id="table_post_oauthClients_endpoints"
        rowsep="0">
        <tgroup align="left" cols="2">
                <colspec colname="col1" colnum="1" colwidth="1*"/>
                <colspec colname="col2" colnum="2" colwidth="3*"/>
                <thead>
                        <row>
                                <entry colname="col1">Parameter</entry>
                                <entry colname="col2">Description</entry>
                        </row>
                </thead>

I'll try referencing the <colspec> element and using the @column value,
but that seems like it will give me the same issue.

..dan



--
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.

XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/1240222> (by
email)
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3481519> (by
email<>)

Current Thread