Skip to content

Instantly share code, notes, and snippets.

@pgundlach
Last active September 7, 2020 10:07
Show Gist options
  • Save pgundlach/3e2c83f7bc765e7b1e8b49a48b16a3ff to your computer and use it in GitHub Desktop.
Save pgundlach/3e2c83f7bc765e7b1e8b49a48b16a3ff to your computer and use it in GitHub Desktop.
Example for table construction
<data>
<entry>E3Q7wpaCuqlEW7IpD5wLZ%EKnL6l6KzJ</entry>
<entry>0wLL7=Y6XKUDw$rS3STaxq6vGnPC,S,s</entry>
<entry>uIB9xFJ7o1c9cpvdW-fuAn8%7V6XjsP5</entry>
<entry>ApBxPOQAeqn1vLBDZgUhsMCa:yoEw3-O</entry>
<entry>XMa0V%Cgp09GLHlGNiby8,2zwHgPqs.r</entry>
<entry>5A;ybcJtNQ.k58Vium=PFdShVJ5X1pg4</entry>
<entry>XFfpSQa2nfVzUgNPwfGDdzu*@6SLAyd3</entry>
<entry>7r@ZQdXckXVzIVTdpg2nEFRJ7h*IZd52</entry>
<entry>GzazyelFpKWU8&amp;79IL.o6k5QS9gq2gVZ</entry>
<entry>6g_@8d6xevl1dZ6PxgP:JPGyFBOIZaQK</entry>
<entry>Lc630l7=WFv*1onSNEAnn1Jz6IrBSYeN</entry>
<entry>pZ6.QFlejK2E5lVvbF@K?p!2BvCz1OOD</entry>
<entry>#O7;;WJWz$fmdBFca95F=CiXFj42uBFJ</entry>
<entry>mCHdL9av$UaK7rywSPS.3xp9$W;:jTej</entry>
<entry>71Tbi1YtYB0F2z9Czv5Bht%rL-o01sH2</entry>
<entry>C+6JBD@8LxWE&amp;Z.2fvjzzDsNnfeZny?u</entry>
<entry>#912kZnJQ2z2aXo6cy#o;j74-CJ668hf</entry>
<entry>2yWO2sHbXBD,@DtmBx9sULGfEJ21vDob</entry>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<!--
This example splits a table onto multiple pages.
Normally the speedata publisher will do it by itself,
this is here for demonstration purpose only. Sometimes you might
need more complicated table break rules and this mechanism will help you.
-->
<Layout xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<Pageformat width="130mm" height="50mm" />
<Trace grid="no" />
<SetGrid height="12pt" nx="10"/>
<LoadFontfile name="CamingoCode-Regular" filename="CamingoCode-Regular.ttf" />
<DefineFontfamily fontsize="10" leading="12" name="tt">
<Regular fontface="CamingoCode-Regular" />
</DefineFontfamily>
<Record element="data">
<PlaceObject>
<Textblock>
<Paragraph>
<Value>My favourite passwords:</Value>
</Paragraph>
</Textblock>
</PlaceObject>
<!-- clear the variable 'tablerows' which is used to collect the
table rows of the previous iterations
-->
<SetVariable variable="tablerows" />
<ForAll select="entry">
<SetVariable variable="thisrow">
<Tr backgroundcolor="lightgray">
<Td>
<Paragraph fontface="tt">
<Value select="position()"/>
<Value>: </Value>
<Value select="." />
</Paragraph>
</Td>
</Tr>
</SetVariable>
<!-- put the previous lines and this line into a table -->
<Group name="tbl">
<Contents>
<PlaceObject>
<Table width="10" stretch="max">
<Copy-of select="$tablerows" />
<Copy-of select="$thisrow" />
</Table>
</PlaceObject>
</Contents>
</Group>
<!-- does it fit on the page? -->
<SetVariable
variable="remaining-height"
select="sd:number-of-rows() - sd:current-row() + 1" />
<Switch>
<Case test="sd:group-height('tbl') > $remaining-height">
<!-- too large, print table without the last row -->
<PlaceObject column="1">
<Table width="10" stretch="max">
<Copy-of select="$tablerows" />
</Table>
</PlaceObject>
<NextRow />
<SetVariable variable="tablerows">
<Copy-of select="$thisrow" />
</SetVariable>
<!-- clear the group -->
<Group name="tbl">
<Contents>
<PlaceObject>
<Table width="10" stretch="max">
<Copy-of select="$thisrow" />
</Table>
</PlaceObject>
</Contents>
</Group>
</Case>
<Otherwise>
<!-- it fits, so we can safely add this row to the list of all rows -->
<SetVariable variable="tablerows">
<Copy-of select="$tablerows" />
<Copy-of select="$thisrow" />
</SetVariable>
</Otherwise>
</Switch>
</ForAll>
<!-- last page -->
<PlaceObject groupname="tbl"/>
</Record>
</Layout>
@pgundlach
Copy link
Author

Result

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment