speedata / publisher

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

avoid requiring `concat()` for page in image-related XPath functions #460

Closed pr-apes closed 1 year ago

pr-apes commented 1 year ago

@pgundlach,

compiling the following source with sp --dummy --jobname=mixed-pages:

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

  <Pagetype name="abcde" test="sd:even(sd:current-page())" width="297mm" height="210mm"/>

  <Record element="data">
    <Loop select="10" variable="pagenum">
      <Output>
        <Text>
          <Paragraph>
            <Value>page</Value>
          </Paragraph>
        </Text>
      </Output>
      <ClearPage/>
    </Loop>
  </Record>
</Layout>

And then using sp --dummy -v pdfdoc=mixed-pages.pdf to compile this source:

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

  <Record element="data">
    <Output>
      <Text>
        <Loop select="sd:number-of-pages($pdfdoc)" variable="pagenum">
          <Paragraph>
            <Value>aspect ratio: </Value>
            <Value select="sd:aspectratio($pdfdoc:$pagenum)"/>
            <Value> file name: </Value>
            <Value select="$pdfdoc"/>
            <Value> page number: </Value>
            <Value select="$pagenum"/>
            <Value> page height: </Value>
            <Value select="sd:imageheight($pdfdoc:$pagenum)"/>
            <Value> page width: </Value>
            <Value select="sd:imagewidth($pdfdoc:$pagenum)"/>
          </Paragraph>
        </Loop>
      </Text>
    </Output>
  </Record>
</Layout>

I get this output:

hola-01-fs8

Of course, version is current latest:

> sp --version
Version: 4.13.6

Am I missing something from the new syntax or is this a bug?

Many thanks for your help.

pr-apes commented 1 year ago

I know now what I was missing.

sd:aspectratio($pdfdoc:$pagenum) should read sd:aspectratio(concat($pdfdoc, ':', $pagenum)).

I wonder whether concat() could be avoided when variables are used.

Many thanks for your help.

pgundlach commented 1 year ago

While I do get the point of the request (I think it makes sense to split the document and the page number), I doubt that I can easily change that. The page number extraction is done after processing the variables and changing that is a task I'd rather avoid (and I might not even find a good solution to keep XPath semantics).

So I'd rather close this as 'can't fix'...

pr-apes commented 1 year ago

Ok, closing the issue myself now.