How to show page number (N of N) using xslt in PDF Report - pdf

I am using XSLT to generate PDF report. My requirements are to display page number in the format of Page N of N (e.g.Page 1 of 3) at the footer of the report. For static values it works fine and it repeats on each page. As total number of pages in the report are not known and it changes run time, so how I will accomplish this task.
My XSLT code snippet
<xsl:template name="footerall">
<xsl:variable name="maxwidth" select="7.07000" />
<fo:static-content flow-name="xsl-region-after">
<fo:block>
<xsl:variable name="tablewidth29" select="$maxwidth * 1.00000" />
<xsl:variable name="sumcolumnwidths29" select="0.04167 + 1.56250 + 0.04167" />
<xsl:variable name="factor29">
<xsl:choose>
<xsl:when
test="$sumcolumnwidths29 > 0.00000 and $sumcolumnwidths29 > $tablewidth29">
<xsl:value-of select="$tablewidth29 div $sumcolumnwidths29" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1.000" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="defaultcolumns29" select="1" />
<xsl:variable name="defaultcolumnwidth29">
<xsl:choose>
<xsl:when test="$factor29 < 1.000">
<xsl:value-of select="0.000" />
</xsl:when>
<xsl:when test="$defaultcolumns29 > 0">
<xsl:value-of
select="($tablewidth29 - $sumcolumnwidths29) div $defaultcolumns29" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0.000" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="columnwidth29_0" select="$defaultcolumnwidth29" />
<xsl:variable name="columnwidth29_1" select="1.56250 * $factor29" />
<fo:table width="{$tablewidth29}in" border-collapse="separate"
border-separation="0.04167in" color="black" display-align="center">
<fo:table-column column-width="{$columnwidth29_0}in" />
<fo:table-column column-width="{$columnwidth29_1}in" />
<fo:table-body>
<fo:table-row>
<fo:table-cell number-columns-spanned="2"
padding-top="0.00000in" padding-bottom="0.00000in" padding-left="0.00000in"
padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt">
<fo:block text-align="center" space-before.optimum="-8pt">
<fo:leader leader-length="100%" leader-pattern="rule"
rule-thickness="1pt" color="black" />
</fo:block>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell
font-size="inherited-property-value(&apos;font-size&apos;) - 2pt"
text-align="left" padding-top="0.00000in" padding-bottom="0.00000in"
padding-left="0.00000in" padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt">
<fo:inline font-family="Courier" font-size="10px">
<xsl:value-of select="$My XPath to varaible" />
</fo:inline>
<fo:inline font-family="Courier" font-size="10px">
<xsl:text> - </xsl:text>
<xsl:text>        </xsl:text>
<xsl:text>Page 1 of 1</xsl:text>
</fo:inline>
<fo:inline font-family="Courier" font-size="10px">
<xsl:value-of select="$My XPath to varaible" />
</fo:inline>
</fo:block>
</fo:table-cell>
<fo:table-cell
font-size="inherited-property-value(&apos;font-size&apos;) - 2pt"
text-align="right" padding-top="0.00000in" padding-bottom="0.00000in"
padding-left="0.00000in" padding-right="0.00000in">
<fo:block padding-top="1pt" padding-bottom="1pt" />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:static-content>
</xsl:template>
I will replace the string (Page 1 of 1) by a variable but how to handle this.
Please help me.

I solved my problem by following below instructions.
Put a formatting object with an id at the end of the area. You can then do a to the labeled block that appears on the last page of the document. Here's how the markup looks:
<fo:flow flow-name="xsl-region-body">
... Lots and lots of content here
<fo:block id="TheVeryLastPage"> </fo:block>
</fo:flow>
The code creates a block with an id of TheVeryLastPage (a value that's unlikely to be used by anyone), and now you can refer to that id to get the page number of the last page of the document. Here's how the content in the area should look:
<fo:block text-align="end">
Page <fo:page-number/> of
<fo:page-number-citation
ref-id="TheVeryLastPage"/>
</fo:block>
When FOP formats this markup, it generates something like "Page 2 of 5".
My reference URL is: http://www.ibm.com/developerworks/xml/tutorials/x-xslfo2/section4.html

You should add an id attribute to your fo:page-sequence element, and then use a page-number-citation-last.
<fo:page-sequence id="my-sequence-id">
...
<xsl:text>Page </xsl:text>
<fo:page-number-citation />
<xsl:text> of </xsl:text>
<fo:page-number-citation-last page-citation-strategy="all" ref-id="my-sequence-id"/>
...
</fo:page-sequence>
See the specs: http://www.w3.org/TR/xslfo20/#fo_page-number-citation and http://www.w3.org/TR/xslfo20/#fo_page-number-citation-last

Related

We are printing images to a pdf using XSL fo. our aim is to print them in row wise but those are printing in column wise. Any suggestions please

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo" xml:space="preserve">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="assets">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="one" page-width="216mm" page-height="279mm" margin-top="10mm" margin-bottom="5mm" margin-left="10mm" margin-right="10mm">
<fo:region-body column-count="5" margin-top="1cm" margin-bottom="1cm"/>
<fo:region-before extent="1cm"/>
<fo:region-after extent="1cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="one">
<fo:static-content flow-name="xsl-region-before">
<fo:table table-layout="fixed" width="100%" font-size="16pt" text-align="center">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select="title"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<!--footer-->
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="8pt" font-family="Arial" text-align="left">All rights reserved.</fo:block>
<fo:block font-family="Arial" font-size="8pt" text-align="right">Page <fo:page-number/>
</fo:block>
</fo:static-content>
<!-- body -->
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="assetExport"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:variable name="width" select="#displayValue"/>
<xsl:template match="assetExport">
<fo:block-container border-color="#D3D3D3" border-style="solid" border-width=".8px" margin-top="4mm" keep-together.within-column="always" width="36mm" height="56mm" scaling="uniform">
<xsl:apply-templates select="thumbnail"/>
<xsl:apply-templates select="metadata"/>
</fo:block-container>
</xsl:template>
<xsl:template match="metadata">
<xsl:apply-templates select="property"/>
</xsl:template>
<!-- Render the images -->
<xsl:template match="thumbnail">
<xsl:variable name="src" select="."/>
<xsl:choose>
<xsl:when test="$src = ''">
<fo:block-container>
<fo:block width="30mm" height="40mm" font-weight="bold" font-size="12pt" text-indent="5mm" margin-top="3mm" margin-bottom="2mm" margin-left="2mm" margin-right="2mm">
<xsl:text width="30mm" height="40mm">No Preview available</xsl:text>
</fo:block>
</fo:block-container>
</xsl:when>
<xsl:otherwise>
<fo:block margin-left="2mm" margin-right="2mm" margin-top="0mm">
<fo:external-graphic src="url(file:///{$src})" width="32mm" text-align="center" display-align="center" content-width="scale-to-fit" height="32mm" content-height="scale-to-fit" scaling="uniform"/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Render the metadata WITH Prompt -->
<xsl:template match="property">
<xsl:choose>
<xsl:when test="#prompt = 'Expiration Date'">
<fo:block margin-left="2mm" wrap-option="wrap" width="34mm" height="30mm" font-family="Arial" font-size="8pt" color="black">
<xsl:value-of select="(concat('Expiration Date: ',substring(child::property-value/attribute::displayValue,0,11)))"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block margin-left="2mm" wrap-option="wrap" width="34mm" height="30mm" font-family="Arial" font-size="8pt" color="black">
<xsl:value-of select="attribute::prompt"/>
<xsl:text> : </xsl:text>
<xsl:value-of select="child::property-value/attribute::displayValue"/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

How to convert some text in paragraph into bold xsl fo?

This is how my xml looks like:
xml:
<Documents>
<Document>
<Note>
<Header>
<HeaderText> <b>Need Help?</b> Contact Our Customer Happiness Team
by phone <b>0345 00002662</b>
Mon-Fri 9am-7pm
</HeaderText>
</Header>
</Note>
</Document>
</Documents>
I want to convert some text in HeaderText in bold. E.g Need Help? Contact Our Customer Happiness Team
by phone 0345 00002662 Mon-Fri 9am-7pm
Xslt:
<fo:table-header text-align="left" border-width="0mm">
<fo:table-row margin-left="1cm" font-family="Avenir" font-size="14pt">
<fo:table-cell>
<fo:block padding-top="0cm">
<xsl:value-of select="HeaderText" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
The <b>Need Help?</b> is just text to the XSLT processor and the XSL-FO formatter.
This is similar to XSLT - How to treat inline/escaped XML within a node as nested nodes. The advice there doesn't get beyond doing it in two passes or using XSLT 2.0 or 3.0.
If <b> is the only non-element that you need to convert into real markup, then you can do it with a recursive template:
<xsl:template match="text()[contains(., '<b>')]"
name="unescape-bold">
<xsl:param name="text" select="." />
<xsl:choose>
<xsl:when test="not(contains($text, '<b>'))">
<xsl:value-of select="$text" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($text, '<b>')" />
<fo:inline font-weight="bold">
<xsl:value-of
select="substring-before(substring-after($text, '<b>'),
'</b>')" />
</fo:inline>
<xsl:call-template name="unescape-bold">
<xsl:with-param name="text"
select="substring-after($text, '</b>')" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
For your sample, this gives:
<fo:inline font-weight="bold">Need Help?</fo:inline> Contact Our Customer Happiness Team
by phone <fo:inline font-weight="bold">0345 00002662</fo:inline>
Mon-Fri 9am-7pm
Check this Code:-
<fo:table-header text-align="left" border-width="0mm">
<fo:table-row margin-left="1cm" font-family="Avenir" font-size="14pt">
<fo:table-cell>
<fo:block padding-top="0cm">
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<xsl:template match="bold">
<fo:inline font-weight="bold">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

How to display thumbnails from harvested items in DSpace?

I am trying to display the thumbnails from harvested items. The settings I have for the harvesting options is Harvest metadata and references to bitstreams (requires ORE support). When looking for the code on how DSpace displays the filenames and file sizes of the bitstreams of the harvested items in simple view, I found that in https://github.com/DSpace/DSpace/blob/dspace-6.1/dspace-xmlui-mirage2/src/main/webapp/xsl/aspect/artifactbrowser/item-view.xsl#L375-L378
<!-- Special case for handling ORE resource maps stored as DSpace bitstreams -->
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="//mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM" />
</xsl:when>
and for the full item record view in https://github.com/DSpace/DSpace/blob/dspace-6.1/dspace-xmlui-mirage2/src/main/webapp/xsl/aspect/artifactbrowser/item-view.xsl#L81-L84.
<!-- Special case for handling ORE resource maps stored as DSpace bitstreams -->
<xsl:when test="./mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="./mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemDetailView-DIM" />
</xsl:when>
So it seems that code found in item-view.xsl is calling the template match found in ORE.xsl.
Now, looking at a sample mets.xml file of a harvested item specifically in //mets:fileSec/mets:fileGrp[#USE='ORE'], we can see that it is referencing the ORE.xml in /bitstream/handle/10862/3360/ORE.xml.
<mets:fileSec>
<mets:fileGrp USE="ORE">
<mets:file GROUPID="group_file_f148a8ad-b7ad-49fe-8b4b-0d3893d2c351" CHECKSUM="7afebcfcf393395503377219395e3926" MIMETYPE="text/xml" SIZE="4137" ID="file_f148a8ad-b7ad-49fe-8b4b-0d3893d2c351" CHECKSUMTYPE="MD5">
<mets:FLocat LOCTYPE="URL" xlink:href="/bitstream/handle/10862/3360/ORE.xml?sequence=1&isAllowed=y" xlink:type="locator" xlink:title="ORE.xml"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
Based on the template match found in ORE.xsl, we can see that the file names and file size was generated from this code:
<xsl:template match="mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM">
<xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[#LOCTYPE='URL']//#*[local-name(.)='href'],$context-path))"/>
<div class="item-page-field-wrapper table">
<h5>
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
</h5>
<xsl:for-each select="document($AtomMapURL)/atom:entry/atom:link[#rel='http://www.openarchives.org/ore/terms/aggregates']">
<xsl:variable name="link_href" select="#href"/>
<xsl:if test="/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href][dcterms:description='ORIGINAL']
or not(/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href])">
<xsl:call-template name="itemSummaryView-DIM-file-section-entry">
<xsl:with-param name="href" select="#href" />
<xsl:with-param name="mimetype" select="#type" />
<xsl:with-param name="label-1" select="'title'" />
<xsl:with-param name="label-2" select="'title'" />
<xsl:with-param name="title" select="#title" />
<xsl:with-param name="label" select="#title" />
<xsl:with-param name="size" select="#length" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
Viewing the /bitstream/handle/10862/3360/ORE.xml, we can see that aside from the ORIGINAL bundle, the TEXT and THUMBNAIL bundles were also captured when it was harvested.
<atom:link href="https://repository.seafdec.org.ph/bitstream/10862/152/1/ediblecrustacea.pdf" length="2310365" rel="http://www.openarchives.org/ore/terms/aggregates" title="ediblecrustacea.pdf" type="application/pdf"/>
<atom:link href="https://repository.seafdec.org.ph/bitstream/10862/152/4/edible-crust-errata.pdf" length="177699" rel="http://www.openarchives.org/ore/terms/aggregates" title="edible-crust-errata.pdf" type="application/pdf"/>
<oreatom:triples>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="http://hdl.handle.net/10862/152/ore.xml#atom">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceItem"/>
<dcterms:modified>2011-06-07T06:45:26Z</dcterms:modified>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/35/edible-crust-errata.pdf.txt">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>TEXT</dcterms:description>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/36/ediblecrustacea.pdf.txt">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>TEXT</dcterms:description>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/1/ediblecrustacea.pdf">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>ORIGINAL</dcterms:description>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/4/edible-crust-errata.pdf">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>ORIGINAL</dcterms:description>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/32/ediblecrustacea.pdf.jpg">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>THUMBNAIL</dcterms:description>
</rdf:Description>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/33/edible-crust-errata.pdf.jpg">
<rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
<dcterms:description>THUMBNAIL</dcterms:description>
</rdf:Description>
</oreatom:triples>
Now my goal is to capture and reuse the url found in /atom:entry/oreatom:triples/rdf:Description[#rdf:about][dcterms:description='THUMBNAIL'] and make it as the src of the thumbnail found in the code for the itemSummaryView-DIM-thumnail and mets:filetemplate, sort of hotlinking to the original thumbnail. By the way, the Files in this item view is not that nice anyway so...
With regards to the displaying of thumbnail in simple view, I'm thinking of having an <xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']"> in the itemSummaryView-DIM-thumbnail template ie:
<xsl:choose>
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']">
<xsl:variable name="src">
<xsl:choose>
<xsl:when test="/mets:METS/mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file[#GROUPID=../../mets:fileGrp[#USE='CONTENT']/mets:file[#GROUPID=../../mets:fileGrp[#USE='THUMBNAIL']/mets:file/#GROUPID][1]/#GROUPID]">
<xsl:value-of
select="/mets:METS/mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file[#GROUPID=../../mets:fileGrp[#USE='CONTENT']/mets:file[#GROUPID=../../mets:fileGrp[#USE='THUMBNAIL']/mets:file/#GROUPID][1]/#GROUPID]/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="//mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Checking if Thumbnail is restricted and if so, show a restricted image -->
<xsl:choose>
<xsl:when test="contains($src,'isAllowed=n')"/>
<xsl:otherwise>
<img class="img-thumbnail" alt="Thumbnail">
<xsl:attribute name="src">
<xsl:value-of select="$src"/>
</xsl:attribute>
</img>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="//mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
</xsl:when>
<xsl:otherwise>
<img class="img-thumbnail" alt="Thumbnail">
<xsl:attribute name="data-src">
<xsl:text>holder.js/100%x</xsl:text>
<xsl:value-of select="$thumbnail.maxheight"/>
<xsl:text>/text:No Thumbnail</xsl:text>
</xsl:attribute>
</img>
</xsl:otherwise>
</xsl:choose>
My problem now is that I don't know how to reference the url for the thumbnail in the ORE.xml file. I noticed also that the name and file size were extracted from the /atom:entry/atom:link[#rel='http://www.openarchives.org/ore/terms/aggregates'] based from the ORE.xsl code above.
Thanks in advance!
UPDATE
Here's what I did:
I modify the [dspace]/config/crosswalks/oai/metadataFormats/ore.xsl of the source server such that it will expose the thumbnails in the <atom:link rel="http://www.openarchives.org/ore/terms/aggregates"> portion of OAI output when using ore as the metadata format, but I have to clean the cache of oai and do a full reimport of OAI in the source server. Also, I have to reset and import the harvest from the harvesting server to include the new generated ORE.xml files. The modification I did was to change line number 67 of ore.xsl from
<xsl:if test="doc:field[#name='name']/text() = 'ORIGINAL'">
into:
<xsl:if test="doc:field[#name='name']/text() = 'ORIGINAL' or doc:field[#name='name']/text() = 'THUMBNAIL'">
Then in item-view.xsl, I included this line in the <xsl:template name="itemSummaryView-DIM-thumbnail">:
Then, in [dspace]/webapps/xmlui/themes/Mirage2/xsl/aspect/artifactbrowser/ORE.xsl I include these lines:
<xsl:template match="mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail">
<xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[#LOCTYPE='URL']//#*[local-name(.)='href'],$context-path))"/>
<xsl:apply-templates select="document($AtomMapURL)/atom:entry/atom:link[#rel='http://www.openarchives.org/ore/terms/aggregates']" mode="itemSummaryView-DIM-thumbnail"/>
</xsl:template>
<xsl:template match="atom:link[#rel='http://www.openarchives.org/ore/terms/aggregates']" mode="itemSummaryView-DIM-thumbnail">
<xsl:variable name="link_href" select="#href"/>
<xsl:if test="/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href][dcterms:description='THUMBNAIL' and position() = 1]
or not(/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href])">
<img class="img-thumbnail" alt="Thumbnail">
<xsl:attribute name="src">
<xsl:value-of select="#href"/>
</xsl:attribute>
</img>
</xsl:if>
</xsl:template>
This worked except that in cases where there are multiple thumbnails in the source item, it will also show more than one thumbnails even though I have in my test condition <xsl:if test="/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href][dcterms:description='THUMBNAIL' and position() = 1] or not(/atom:entry/oreatom:triples/rdf:Description[#rdf:about=$link_href])">. See screenshot below:
Also, I would rather not modify the ore.xsl in the crosswalk directory of the source server hence this post: Extract attribute value if child node contains this text
UPDATE 2 - Thumbnail is now displayed in simple item view
What I did:
In <xsl:template name="itemSummaryView-DIM-thumbnail">, I inserted the code below after line# 195:
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="//mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
</xsl:when>
Then, I added this templates in ORE.xsl:
<xsl:template match="mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail">
<xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[#LOCTYPE='URL']//#*[local-name(.)='href'],$context-path))"/>
<xsl:apply-templates select="document($AtomMapURL)/atom:entry/oreatom:triples" mode="itemSummaryView-DIM-thumbnail"/>
</xsl:template>
<xsl:template match="oreatom:triples" mode="itemSummaryView-DIM-thumbnail">
<xsl:if test="/atom:entry/oreatom:triples/rdf:Description[dcterms:description='THUMBNAIL']
or not(/atom:entry/oreatom:triples/rdf:Description)">
<img class="img-thumbnail" alt="Thumbnail">
<xsl:attribute name="src">
<xsl:value-of select="rdf:Description[boolean(#rdf:about) and
.//dcterms:description[. = 'THUMBNAIL']][1]/#rdf:about"/>
</xsl:attribute>
</img>
</xsl:if>
</xsl:template>
My harvested item is now displaying the thumbnail in item summary view:
It would really be great if I can also make the thumbnails display in the item list and search results but for now, I can't figure out how to match and select the thumbnail url. I don't know how to reference them from within the <xsl:template match="mets:fileSec" mode="artifact-preview"> template.
For my future reference, this is what I have made to show the thumbnails for harvested items.
This answer is based on DSpace 5x Mirage2 Theme but it can also be applied to DSpace 6x Mirage2.
In item-view.xsl, locate the <xsl:template name="itemSummaryView-DIM-thumbnail"> block and then insert this code:
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="//mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
</xsl:when>
before the <xsl:otherwise> block. Complete template block below:
<xsl:template name="itemSummaryView-DIM-thumbnail">
<div class="thumbnail">
<xsl:choose>
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']">
<xsl:variable name="src">
<xsl:choose>
<xsl:when test="/mets:METS/mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file[#GROUPID=../../mets:fileGrp[#USE='CONTENT']/mets:file[#GROUPID=../../mets:fileGrp[#USE='THUMBNAIL']/mets:file/#GROUPID][1]/#GROUPID]">
<xsl:value-of
select="/mets:METS/mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file[#GROUPID=../../mets:fileGrp[#USE='CONTENT']/mets:file[#GROUPID=../../mets:fileGrp[#USE='THUMBNAIL']/mets:file/#GROUPID][1]/#GROUPID]/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="//mets:fileSec/mets:fileGrp[#USE='THUMBNAIL']/mets:file/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<img alt="Thumbnail">
<xsl:attribute name="src">
<xsl:value-of select="$src"/>
</xsl:attribute>
</img>
</xsl:when>
<xsl:when test="//mets:fileSec/mets:fileGrp[#USE='ORE']">
<xsl:apply-templates select="//mets:fileSec/mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
</xsl:when>
<xsl:otherwise>
<img alt="Thumbnail">
<xsl:attribute name="data-src">
<xsl:text>holder.js/100%x</xsl:text>
<xsl:value-of select="$thumbnail.maxheight"/>
<xsl:text>/text:No Thumbnail</xsl:text>
</xsl:attribute>
</img>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
Then edit ORE.xsl and insert the code below just before the </xsl:stylesheet> ending tag.
<xsl:template match="mets:fileGrp[#USE='ORE']" mode="itemSummaryView-DIM-thumbnail">
<xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[#LOCTYPE='URL']//#*[local-name(.)='href'],$context-path))"/>
<xsl:apply-templates select="document($AtomMapURL)/atom:entry/oreatom:triples" mode="itemSummaryView-DIM-thumbnail"/>
</xsl:template>
<xsl:template match="oreatom:triples" mode="itemSummaryView-DIM-thumbnail">
<xsl:if test="/atom:entry/oreatom:triples/rdf:Description[dcterms:description='THUMBNAIL']
or not(/atom:entry/oreatom:triples/rdf:Description)">
<img alt="Thumbnail" class="img-responsive">
<xsl:attribute name="src">
<xsl:value-of select="rdf:Description[boolean(#rdf:about) and
.//dcterms:description[. = 'THUMBNAIL']][1]/#rdf:about"/>
</xsl:attribute>
</img>
</xsl:if>
</xsl:template>
To show the thumbnails in item list, edit common.xsl and locate this code:
<xsl:text>?sections=dmdSec,fileSec&fileGrpTypes=THUMBNAIL</xsl:text>
and change it to:
<xsl:text>?sections=dmdSec,fileSec&fileGrpTypes=THUMBNAIL,ORE</xsl:text>
To show thumbnails in search results, locate that same line of code above in the file discovery.xsl found under [dspace-src]/dspace/modules/xmlui-mirage2/src/main/webapp/themes/Mirage2/xsl/aspect/discovery directory and modify it just like in the common.xsl file.
All file modifications in this answer are made under the [dspace-src]dspace/modules directory.
Example of this code in action can be found here: SEAFDEC External Publications

xslt change writing-mode to FA is metadata language is FA

I'm working in the xsl-file "generate_document_structure.xsl" and a'm not so familiar with this older structure.
My goal in this is to change the writing-mode from lr-tb to rl-tb if the language in the METADATA is FA or AR.
Below a cleaned-up piece of code from the ouputfolder
<?xml version="1.0" encoding="UTF-8"?>
<fctdcl>
<publicationinfo dclselection="SelectedNode">
<props>
<attrblock type="1toN" name="language">
<attrlist>
<attrdesc id="1" name="language"/>
</attrlist>
<attrrec>
<attrval id="1">Default</attrval>
</attrrec>
</attrblock>
</props>
</publicationinfo>
It is a big guess for my how to make the connection to the METADATA if the language is FA. in other words, i'm looking for the wright xpath to the METADATA and select the value of it.
i was thinking in the way like below:
<xsl:variable name="language">
<xsl:value-of select="//*[contains(#class, ' /FCTDocuments/metadata/#language ')]/#content"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when test="$language = 'FA'">
<xsl:attribute name="writing-mode">rl-tb</xsl:attribute>
</xsl:when>
</xsl:choose>
I would appreciate it if someone could help me in this
#Toni,
I made some steps with it.
Below my current file.
<xsl:template name="FoT_page-sequence_ContentSequence">
<xsl:choose>
<xsl:when test="not(/FCTDocuments/chapter)">
<fo:page-sequence master-reference="ContentSequence">
<xsl:call-template name="AddHyphenationToSequence"/>
<xsl:call-template name="chapter_header_footer_without_config"/>
<fo:flow flow-name="xsl-region-body" xsl:use-attribute-sets="XSL_Content">
<fo:block id="last-page"/>
</fo:flow>
</fo:page-sequence>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="/FCTDocuments/chapter">
<fo:page-sequence master-reference="ContentSequence" initial-page-number="auto-odd" writing-mode="rl-tb"> <!---->
<xsl:if test="/FCTDocuments/#RSKM-ProductType = 'MM' ">
<xsl:attribute name="initial-page-number">
<xsl:text>1</xsl:text>
</xsl:attribute>
</xsl:if>
<fo:flow flow-name="xsl-region-body" xsl:use-attribute-sets="XSL_Content">
<xsl:if test="count(preceding-sibling::chapter) = 0">
<xsl:if test="$DEBUG = 'true'">
<!-- write debug informations -->
<xsl:comment>
<xsl:text>DEBUG: Starting Content creation</xsl:text>
</xsl:comment>
</xsl:if>
<fo:block>
<fo:marker marker-class-name="DOCUMENTNAME">
<xsl:value-of select="/FCTDocuments/Cover/CoverTitle"/>
</fo:marker>
<fo:marker marker-class-name="DOCUMENTINFO">
<xsl:value-of select="$DOCUMENTINFO"/>
</fo:marker>
</fo:block>
</xsl:if>
<xsl:apply-templates select="."/>
<xsl:if test="count(following-sibling::chapter) = 0">
<fo:block id="last-page"/>
</xsl:if>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
As we zoom in at the codepart below i added the attribure "writing-mode" in the fo:page-sequence. And after a test it worked fine, But this must only happend when the language is FA
So no i need to make a choose of if statement like test="/FCTDocuments/#RSKM-Language = 'FA'">
how do I manage that if the lang-attribute is FA
<fo:page-sequence master-reference="ContentSequence" initial-page-number="auto-odd" writing-mode="rl-tb"> <!---->
<xsl:if test="/FCTDocuments/#RSKM-ProductType = 'MM' ">
<xsl:attribute name="initial-page-number">
<xsl:text>1</xsl:text>
</xsl:attribute>
</xsl:if>
You initially said you were looking for the right XPath to select your METADATA/metadata, which is why I was asking to see the language code in your source XML.
I am guessing that this is what you want:
<xsl:if test="/FCTDocuments/#RSKM-Language = 'FA'">
<xsl:attribute name="writing-mode">rl</xsl:attribute>
</xsl:if>
You can then omit the writing-mode property on the fo:page-sequence since the default writing-mode value is lr-tb.

Generating PDF in 11 * 17 (Landscape) with XSLT

I have this requirement wherein I need to create a PDS in 11 * 17 size and in landscape format with XSLT. I am able to create PDF in A4 page size using XSl FO.
My XSLT is as follow:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family = "Helvetica" font-size = "10px">
<fo:layout-master-set>
<fo:simple-page-master margin-bottom="0.5cm" margin-left="0.75cm" margin-right="0.75cm" margin-top="0.5cm" master-name="first" page-height="27.9cm" page-width="21.6cm">
<fo:region-body margin-bottom = "0.5cm" margin-top = "0.25cm"/>
<fo:region-before extent = "0cm"/>
<fo:region-after extent = "0.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:for-each select="Rowsets">
<fo:page-sequence master-reference="first">
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="8pt" line-height="6pt" text-align-last="justify">
Shift Report
<fo:inline id="Date">
Date [currentDate]
</fo:inline>
<fo:leader leader-pattern = "space"/>
Page
<fo:page-number/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:for-each select="Rowset">
<xsl:choose>
<xsl:when test="Columns/Column[1]/#Description = 'Break'">
<fo:block page-break-before="always" />
</xsl:when>
<xsl:otherwise>
<fo:table border-color="black" border-style="solid" border-width="1pt" table-layout="fixed" width="100%">
<xsl:variable name="columns">
<xsl:value-of select="count(Columns/Column)" />
</xsl:variable>
<xsl:for-each select="Columns/Column">
<xsl:choose>
<xsl:when test="position()<2">
<fo:table-column column-width="62pt" />
</xsl:when>
<xsl:when test="position()>1 and position()<4">
<fo:table-column column-width="40pt" />
</xsl:when>
<xsl:when test="position()>4 and position()<6">
<fo:table-column column-width="40pt" />
</xsl:when>
<xsl:when test="position()>8">
<fo:table-column column-width="60pt" />
</xsl:when>
<xsl:otherwise>
<fo:table-column />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<fo:table-body font-size="10pt">
<fo:table-row height="13pt">
<fo:table-cell background-color="#000000" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt" number-columns-spanned="{$columns}">
<fo:block font-weight="bold" text-align="center" color="#FFFFFF">
Shift Report
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row height="13pt">
<xsl:for-each select="Columns/Column">
<fo:table-cell background-color="#CCCCCC" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt">
<fo:block font-weight="bold" text-align="left">
<xsl:value-of select="translate(#Name,'_',' ')" />
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
<xsl:for-each select="Row">
<fo:table-row height="13pt">
<xsl:for-each select="child::*">
<fo:table-cell background-color="#FFFFFF" border-style="solid" border-width="1pt" padding-left="5pt" padding-top="5pt">
<fo:block font-weight="normal" text-align="left">
<xsl:value-of select="." />
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
<fo:block text-indent="2pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt">
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
</xsl:stylesheet>
I am not sure where does have to make change in order to accomodate 11 * 17 size and landscape orientation.
Also, one of the column(header) name is "QualityPercent". I would like to change it to "Quality%"
Can anyone help?
Change page-height="27.9cm" page-width="21.6cm" to page-height="11in" page-width="17in".
There's also the size shorthand (see https://www.w3.org/TR/xsl11/#size). If it's supported, you can use size="17in 11in". Some formatters (including AH Formatter: https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#axf.size) recognise some set of keywords for the paper size, such that you can also use size="Ledger".
Edited:
Change:
<xsl:value-of select="translate(#Name,'_',' ')" />
to
<xsl:choose>
<xsl:when test="contains(#Name, 'Percent')">
<xsl:value-of select="substring-before(#Name, 'Percent')" />
<xsl:text>%</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(#Name,'_',' ')" />
</xsl:otherwise>
</xsl:choose>
If you were using XSLT 2.0 (or 3.0), you could use replace() to more easily and accurately replace Percent with % in any #Name value.