Skip to content

Commit dcd7e74

Browse files
Merge pull request #748 from metanorma/fileattachment_annotation
Fileattachment annotation
2 parents 6af6910 + 44de812 commit dcd7e74

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ XSLT_GENERATED := xslt/iec.international-standard.xsl \
8181
xslt/bipm.rapport.xsl \
8282
xslt/jcgm.standard.xsl
8383

84-
MN2PDF_DOWNLOAD_PATH := https://github.com/metanorma/mn2pdf/releases/download/v2.00/mn2pdf-2.00.jar
84+
MN2PDF_DOWNLOAD_PATH := https://github.com/metanorma/mn2pdf/releases/download/v2.01/mn2pdf-2.01.jar
8585
# MN2PDF_DOWNLOAD_PATH := https://maven.pkg.github.com/metanorma/mn2pdf/com/metanorma/fop/mn2pdf/1.7/mn2pdf-1.7.jar
8686
MN2PDF_EXECUTABLE := $(notdir $(MN2PDF_DOWNLOAD_PATH))
8787

xslt_src/common.xsl

+30-5
Original file line numberDiff line numberDiff line change
@@ -12373,14 +12373,16 @@
1237312373
<xsl:template match="*[local-name()='link']" name="link">
1237412374
<xsl:variable name="target_normalized" select="translate(@target, '\', '/')"/>
1237512375
<xsl:variable name="target_attachment_name" select="substring-after($target_normalized, '_attachments/')"/>
12376+
<xsl:variable name="isLinkToEmbeddedFile" select="normalize-space(@attachment = 'true' and $pdfAttachmentsList//attachment[@filename = current()/@target])"/>
1237612377
<xsl:variable name="target">
1237712378
<xsl:choose>
1237812379
<xsl:when test="@updatetype = 'true'">
1237912380
<xsl:value-of select="concat(normalize-space(@target), '.pdf')"/>
1238012381
</xsl:when>
1238112382
<!-- link to the PDF attachment -->
12382-
<xsl:when test="@attachment = 'true' and $pdfAttachmentsList//attachment[@filename = current()/@target]">
12383-
<xsl:value-of select="concat('url(embedded-file:', @target, ')')"/>
12383+
<xsl:when test="$isLinkToEmbeddedFile = 'true'">
12384+
<xsl:variable name="target_file" select="java:org.metanorma.fop.Util.getFilenameFromPath(@target)"/>
12385+
<xsl:value-of select="concat('url(embedded-file:', $target_file, ')')"/>
1238412386
</xsl:when>
1238512387
<!-- <xsl:when test="starts-with($target_normalized, '_') and contains($target_normalized, '_attachments/') and $pdfAttachmentsList//attachment[@filename = $target_attachment_name]">
1238612388
<xsl:value-of select="concat('url(embedded-file:', $target_attachment_name, ')')"/>
@@ -12411,6 +12413,11 @@
1241112413
<xsl:attribute name="keep-together.within-line">always</xsl:attribute>
1241212414
</xsl:if>
1241312415

12416+
<xsl:if test="$isLinkToEmbeddedFile = 'true'">
12417+
<xsl:attribute name="color">inherit</xsl:attribute>
12418+
<xsl:attribute name="text-decoration">none</xsl:attribute>
12419+
</xsl:if>
12420+
1241412421
<xsl:call-template name="refine_link-style"/>
1241512422

1241612423
<xsl:choose>
@@ -12433,6 +12440,10 @@
1243312440
</xsl:otherwise>
1243412441
</xsl:choose>
1243512442
</fo:basic-link>
12443+
<xsl:if test="$isLinkToEmbeddedFile = 'true'">
12444+
<!-- reserve space at right for PaperClip icon -->
12445+
<fo:inline keep-with-previous.within-line="always">&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;</fo:inline>
12446+
</xsl:if>
1243612447
</xsl:with-param>
1243712448
</xsl:call-template>
1243812449
</xsl:otherwise>
@@ -19795,9 +19806,14 @@
1979519806
</x:xmpmeta>
1979619807
<!-- add attachments -->
1979719808
<xsl:for-each select="//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment']">
19798-
<xsl:variable name="description" select="normalize-space(//*[local-name() = 'bibitem'][@hidden = 'true'][*[local-name() = 'uri'][@type = 'attachment'] = current()/@name]/*[local-name() = 'formattedref'])"/>
19809+
<xsl:variable name="bibitem_attachment_" select="//*[local-name() = 'bibitem'][@hidden = 'true'][*[local-name() = 'uri'][@type = 'attachment'] = current()/@name]"/>
19810+
<xsl:variable name="bibitem_attachment" select="xalan:nodeset($bibitem_attachment_)"/>
19811+
<xsl:variable name="description" select="normalize-space($bibitem_attachment/*[local-name() = 'formattedref'])"/>
19812+
<xsl:variable name="filename" select="java:org.metanorma.fop.Util.getFilenameFromPath(@name)"/>
19813+
<!-- Todo: need update -->
19814+
<xsl:variable name="afrelationship" select="normalize-space($bibitem_attachment//*[local-name() = 'span'][@class = 'pdf-AFRelationship'])"/>
1979919815

19800-
<pdf:embedded-file filename="{@name}" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf">
19816+
<pdf:embedded-file filename="{$filename}" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf" link-as-file-annotation="true">
1980119817
<xsl:attribute name="src">
1980219818
<xsl:choose>
1980319819
<xsl:when test="normalize-space() != ''">
@@ -19813,18 +19829,27 @@
1981319829
<xsl:if test="$description != ''">
1981419830
<xsl:attribute name="description"><xsl:value-of select="$description"/></xsl:attribute>
1981519831
</xsl:if>
19832+
<xsl:if test="$afrelationship != ''">
19833+
<xsl:attribute name="afrelationship"><xsl:value-of select="$afrelationship"/></xsl:attribute>
19834+
</xsl:if>
1981619835
</pdf:embedded-file>
1981719836
</xsl:for-each>
1981819837
<!-- references to external attachments (no binary-encoded within the Metanorma XML file) -->
1981919838
<xsl:if test="not(//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment'])">
1982019839
<xsl:for-each select="//*[local-name() = 'bibitem'][@hidden = 'true'][*[local-name() = 'uri'][@type = 'attachment']]">
1982119840
<xsl:variable name="attachment_path" select="*[local-name() = 'uri'][@type = 'attachment']"/>
19841+
<xsl:variable name="attachment_name" select="java:org.metanorma.fop.Util.getFilenameFromPath($attachment_path)"/>
1982219842
<xsl:variable name="url" select="concat('url(file:///',$basepath, $attachment_path, ')')"/>
1982319843
<xsl:variable name="description" select="normalize-space(*[local-name() = 'formattedref'])"/>
19824-
<pdf:embedded-file src="{$url}" filename="{$attachment_path}" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf">
19844+
<!-- Todo: need update -->
19845+
<xsl:variable name="afrelationship" select="normalize-space(.//*[local-name() = 'span'][@class = 'pdf-AFRelationship'])"/>
19846+
<pdf:embedded-file src="{$url}" filename="{$attachment_name}" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf" link-as-file-annotation="true">
1982519847
<xsl:if test="$description != ''">
1982619848
<xsl:attribute name="description"><xsl:value-of select="$description"/></xsl:attribute>
1982719849
</xsl:if>
19850+
<xsl:if test="$afrelationship != ''">
19851+
<xsl:attribute name="afrelationship"><xsl:value-of select="$afrelationship"/></xsl:attribute>
19852+
</xsl:if>
1982819853
</pdf:embedded-file>
1982919854
</xsl:for-each>
1983019855
</xsl:if>

0 commit comments

Comments
 (0)