Suppose i have a directory with n images. I would like to add one image per page.
For example :
In a directory called "Images", i have the below 2 images:
newpage0.jpg and newpage1.jpg
I would like to map each image on a single page. How do i dynamically create page-sequences for the number of images present in the directory? The below code works fine for one image.
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:external-graphic src="url(Images/newpage0.jpg)" width="100%"
scaling="uniform" content-width="scale-to-fit" />
</fo:block>
</fo:flow>
</fo:page-sequence>
Please help.
To allow you mark your question as solved, I post my comment as an answer.
The current version of XSLT is 3.0, and has been that since 2017. In the Java world where you use Apache FOP you can easily use XSLT 3.0 with the current version 12(.4) of Saxon HE, available on Github and Maven.
In XSLT 3.0 there is the XPath 3.1 function uri-collection
that, with some vendor specific extension, for Saxon allows you to select e.g. uri-collection('Images/?select=*.jpg')
to have a sequence of collection URIs of jpg files in that directory and then you can use any construct you know or like in XSLT 3 (xsl:apply-templates select="uri-collection('Images/?select=*.jpg')
, xsl:for-each select="uri-collection('Images/?select=*.jpg')"
, xsl:iterate select="uri-collection('Images/?select=*.jpg')"
) to process the sequence and output a fo:page-sequence
for each item in the sequence.