speedata / publisher

speedata Publisher - a professional database Publishing system
https://www.speedata.de/
GNU Affero General Public License v3.0
301 stars 36 forks source link

String global variables let Publisher fail #620

Closed Cicorione closed 3 weeks ago

Cicorione commented 3 weeks ago

Hi @pgundlach

I am not sure if this behavior is correct but global variables, I mean outside any record, when are strings let Publisher fail the PDF generation:

Run speedata publisher 4.19.26
attempt to index a nil value
stack traceback:
    [C]: in for iterator 'for iterator'
    /home/freezr/git/publisher/src/lua/lxpath.lua:1112: in method 'childaxis'
    /home/freezr/git/publisher/src/lua/lxpath.lua:2462: in function </home/freezr/git/publisher/src/lua/lxpath.lua:2457>
    (...tail calls...)
    /home/freezr/git/publisher/src/lua/publisher/commands.lua:4009: in function 'publisher.commands.setvariable'
    /home/freezr/git/publisher/src/lua/publisher.lua:814: in function 'publisher.dispatch'
    /home/freezr/git/publisher/src/lua/publisher.lua:1456: in function 'publisher.initialize_luatex_and_generate_pdf'
    /home/freezr/git/publisher/src/lua/publisher.lua:1153: in function 'publisher.dothings'
    /home/freezr/git/publisher/src/lua/publisher/spinit.lua:358: in function 'main_loop'
    /home/freezr/git/publisher/src/lua/publisher/spinit.lua:369: in main chunk
    [C]: in function 'require'
    [\directlua]:1: in main chunk.
l.5 \directlua{require("publisher.spinit")}

Finished with 0 errors and 0 warnings
No output written
Transcript written to publisher-protocol.xml
exit status 1
Total run time: 564ms

Layout:

<Layout xmlns="urn:speedata.de:2009/publisher/en">

  <!-- this is the β€œhello world” of tables -->
  <Options crop="3mm"/>

  <SetVariable variable="MONTH" select="January"/>
  <SetVariable variable="YEAR" select="2020"/>

  <Record element="data">
    <PlaceObject>
      <Table width="5" stretch="max" padding="2pt">
    <Tr>
          <Td align="left"><Paragraph><Value select="$MONTH" /></Paragraph></Td>
          <Td align="right"><Paragraph><Value select="$YEAR" /></Paragraph></Td>
        </Tr>
        <Tr>
          <Td align="left"><Paragraph><Value>Article number</Value></Paragraph></Td>
          <Td align="right"><Paragraph><Value>Price (Euro)</Value></Paragraph></Td>
        </Tr>
        <ForAll select="entry">
          <Tr>
            <Td align="left"><Paragraph><Value select="@artno"/></Paragraph></Td>
            <Td align="right"><Paragraph><Value select="@price"/></Paragraph></Td>
          </Tr>
        </ForAll>
      </Table>
    </PlaceObject>
  </Record>
</Layout>

Data:

<data>
  <entry artno="99323" price="113,12" />
  <entry artno="28811" price="98,99" />
  <entry artno="12992" price="717,33" />
</data>

Thanks πŸ™

pgundlach commented 3 weeks ago

The error message sucks... But the code is incorrect:

<SetVariable variable="MONTH" select="January"/>
<SetVariable variable="YEAR" select="2020"/>

selects the XML nodes 'January' and '2020' (I believe that this is even an invalid name) of a non-existent XML node.

You probably mean

<SetVariable variable="MONTH" select="'January'"/>
<SetVariable variable="YEAR" select="'2020'"/>

(the apostrophes in the select attribute)

which selects the strings January and 2020

(untested)

Cicorione commented 3 weeks ago

My bad… πŸ˜–

But I tested the global variables and are working the way I expected. πŸ‘

I am pretty sure I already asked about that and you already explained this to me. πŸ€¦β€β™‚οΈ

As a matter of fact after your reply I rechecked the documentation and I found this example:

<SetVariable variable="greeting" select="'Hello User'"/>

I totally missed the apostrophes, now I made some assumptions, because numbers and values don't need to be within apostrophes:

While:

Are my assumptions correct? πŸ€·β€β™‚οΈ

Thanks! πŸ™

pgundlach commented 3 weeks ago
  • select="1234" β€” this is a mathematical variable

correct, although not a variable but a constant.

  • select="$A" β€” this is a mathematical variable too

no, this is an XPath expression that copies the content of the variable A (but a perfectly valid expression). A might contain a number or a string, but also a document or an XML fragment or any other sequence of items.

While:

  • select="'myText'" β€” this is a text string
  • select="'$A'" β€” this is a text string too

both correct.

pgundlach commented 3 weeks ago

I'll close this issue and fix the error message in #621

pgundlach commented 3 weeks ago

This will fix the error message only, not the cause of the issue (which I believe, is not really fixable unless I introduce a new command)