Re: [xsl] Doing math in XSLT?

Subject: Re: [xsl] Doing math in XSLT?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 1 Apr 2024 18:49:28 -0000
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 <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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.

Current Thread