speedata / publisher

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

lxpath / XPath parser bug #546

Closed Cicorione closed 6 months ago

Cicorione commented 6 months ago

Hi @pgundlach

I believe I was able to reproduce the bug I was stepped in while looking to use new lxpath parser: ../@attribute. I don't believe my layout code is incorrect:

data

<data>
    <Parent title="SP Color Test" accent="spyellow">
        <Child>
            <Nephew>
                <Baby>This is box: </Baby>
                <Baby>1</Baby>
            </Nephew>
        </Child>
        <Child>
            <Nephew>
                <Baby>This is box: </Baby>
                <Baby>2</Baby>
            </Nephew>
        </Child>
        <Child>
            <Nephew>
                <Baby>This is box: </Baby>
                <Baby>3</Baby>
            </Nephew>
        </Child>
        <Child>
            <Nephew>
                <Baby>This is box: </Baby>
                <Baby>4</Baby>
            </Nephew>
        </Child>
    </Parent>
</data>

layout

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

    <!-- Basic -->

    <Trace grid="yes"/>
    <Pageformat width="10cm" height="12cm"/>

    <!-- Colors -->

    <DefineColor name="spyellow" model="RGB" r="255" g="178" b="25" alpha="70"/>
    <DefineColor name="spred" model="RGB" r="250" g="25" b="25" alpha="80"/>

    <!-- Basic Master -->

    <Pagetype name="test" test="true()">

        <Margin left="1cm" right="1cm" top="2cm" bottom="1cm" />

        <AtPageCreation>
            <PlaceObject row="10mm" column="0mm">
                <Textblock width="10cm">
                    <Paragraph textformat="centered">
                        <Value>Header's name: </Value>
                            <Color name="{$colortitle}">
                                <Value select="$title" />
                            </Color>
                        </Paragraph>
                    </Textblock>
                </PlaceObject>

                <Message select="concat('Header: ',$colortitle)" />
        </AtPageCreation>

    </Pagetype>

    <!-- General Record -->

    <Record element="data">
        <ProcessNode select="*"/>
    </Record>

    <!-- Record Parent -->

    <Record element="Parent">
        <SetVariable variable="title" select="@title" />
        <SetVariable variable="colortitle" select="@accent" />

        <ProcessNode select="Child" />

        <Message select="concat('Process Node Parent:',@accent)" />

    </Record>

    <!-- Record Child -->

    <Record element="Child">

        <SetGrid nx="2" ny="2" />

        <ForAll select="Nephew">

            <SetVariable variable="color" select="../@accent" />

            <Message select="concat('The color is: ', $color)" />

            <Group name="box">
                <Grid width="1cm" height="1cm" />
                <Contents>

                    <!-- Box -->
                    <ForAll select="Baby">
                    <PlaceObject column="1.3">
                        <Frame backgroundcolor="{$color}" 
                        framecolor="{$color}"
                        border-bottom-left-radius="2mm" 
                        border-bottom-right-radius="2mm" 
                        border-top-left-radius="2mm" 
                        border-top-right-radius="2mm">
                        <Table width="5" padding="2mm">
                            <Tr>
                                <Td valign="middle" align="center">
                                    <Paragraph>
                                        <Value select="." />
                                    </Paragraph>
                                </Td>
                            </Tr>
                        </Table>
                    </Frame>
                </PlaceObject>
            </ForAll>

                </Contents>
            </Group>

            <PlaceObject groupname="box" />

        </ForAll>

    </Record>

</Layout>

When I check the protocol I see something wrong:

Protocol file for speedata Publisher (4.15.16 (Pro))
[...]
Message: "Header: spyellow"
Create Group "box".
Number of rows: 120, number of columns = 10
Warning: [page 1] Background: Color "\
                " is not defined
Error: [page 1] Color "\
                " is not defined
PlaceObject: Table at (1,1) wd/ht: 3/1 in "box" (p. 1)
Warning: [page 1] Background: Color "\
                " is not defined
Error: [page 1] Color "\
                " is not defined
PlaceObject: Table at (1,2) wd/ht: 1/1 in "box" (p. 1)
PlaceObject: Group (box) at (1,1) wd/ht: 1/1 in "_page" (p. 1)
Selecting node: "Child", mode="", pos=2
Message: "The color is: \
                This is box: \
                2\
            "
Re-use Group "box".
[...]

This is apply on the same version on Win/Linux/FreeBSD.

spcolor7.pdf

Thanks... 🙏

pgundlach commented 6 months ago

This works as expected.

When the focus is in "Nephew", the XPath expression must be ../../@accent (two levels up and then the attribute @accent)

<SetVariable variable="color" select="../../@accent" />

(line 63)

Cicorione commented 6 months ago

Hi Patrick, coding is not my expertise, so I am not sure how it should work, but I did as you suggested: ../../@accent and I continue to get the same error:

<SetVariable variable="color" select="../../@accent" />
<Message select="concat('The color is: ', $color)" />

And this is the output of the message:

Message: "The color is: \
                This is box: \
                1\
            "

But accent is here:

<data>
    <Parent title="SP Color Test" accent="spyellow">
[...]
</data>

While the text in the message belong to these tags:

<Baby>This is box: </Baby>
<Baby>1</Baby>

spcolor7b.pdf

Going upper: ../../../@accent did not change anything:

spcolor7c.pdf

Unless I really I didn't get what is the purpose on this new parser, which I do not exclude as possibility, the point is I am recalling a specific attribute, so eventually I expect a nil value not value from other tags.

Thanks.

pgundlach commented 6 months ago

Can you send me the log file, the layout and the data file running in verbose mode?

Cicorione commented 6 months ago

There you go:

data.xml.txt spcolor7.xml.txt spcolor7b.pdf spcolor7b.protocol.txt

Thanks... 🙏

pgundlach commented 6 months ago

You are not using lxpath. Please run sp --xpath lxpath.

Cicorione commented 6 months ago

Oh I see, I was unaware about such command!

Using sp --xpath lxpath works fine on my end!

Cicorione commented 6 months ago

In the news I read this is going to be the default parser the next major version, isn't it?

pgundlach commented 6 months ago

In the news I read this is going to be the default parser the next major version, isn't it?

Yes, there is no ETA yet. I will release it when there are no more bug reports ;-)

(I guess it will be beginning of 2024)