lib/isodoc/iho/iho.specification.xsl in metanorma-iho-0.9.12 vs lib/isodoc/iho/iho.specification.xsl in metanorma-iho-1.0.0

- old
+ new

@@ -6965,22 +6965,37 @@ <!-- END: math --> <!-- ======================================= --> <xsl:template match="*[local-name()='localityStack']"/> + <xsl:variable name="pdfAttachmentsList_"> + <xsl:for-each select="//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment']"> + <attachment filename="{@name}"/> + </xsl:for-each> + </xsl:variable> + <xsl:variable name="pdfAttachmentsList" select="xalan:nodeset($pdfAttachmentsList_)"/> + <xsl:template match="*[local-name()='link']" name="link"> + <xsl:variable name="target_normalized" select="translate(@target, '\', '/')"/> + <xsl:variable name="target_attachment_name" select="substring-after($target_normalized, '_attachments/')"/> <xsl:variable name="target"> <xsl:choose> <xsl:when test="@updatetype = 'true'"> <xsl:value-of select="concat(normalize-space(@target), '.pdf')"/> </xsl:when> + <!-- link to the PDF attachment --> + <xsl:when test="$pdfAttachmentsList//attachment[@filename = current()/@target]"> + <xsl:value-of select="concat('url(embedded-file:', @target, ')')"/> + </xsl:when> + <!-- <xsl:when test="starts-with($target_normalized, '_') and contains($target_normalized, '_attachments/') and $pdfAttachmentsList//attachment[@filename = $target_attachment_name]"> + <xsl:value-of select="concat('url(embedded-file:', $target_attachment_name, ')')"/> + </xsl:when> <xsl:when test="contains(@target, concat('_', $inputxml_filename_prefix, '_attachments'))"> - <!-- link to the PDF attachment --> <xsl:variable name="target_" select="translate(@target, '\', '/')"/> <xsl:variable name="target__" select="substring-after($target_, concat('_', $inputxml_filename_prefix, '_attachments', '/'))"/> <xsl:value-of select="concat('url(embedded-file:', $target__, ')')"/> - </xsl:when> + </xsl:when> --> <xsl:otherwise> <xsl:value-of select="normalize-space(@target)"/> </xsl:otherwise> </xsl:choose> </xsl:variable> @@ -11568,10 +11583,21 @@ <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image'] | *[local-name() = 'sourcecode'] | *[local-name() = 'bibdata'] | *[local-name() = 'localized-strings']" mode="update_xml_step1"> <xsl:copy-of select="."/> </xsl:template> + <xsl:template match="*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment']" mode="update_xml_step1"> + <xsl:copy> + <xsl:copy-of select="@*"/> + <xsl:variable name="name_filepath" select="concat($inputxml_basepath, @name)"/> + <xsl:variable name="file_exists" select="normalize-space(java:exists(java:java.io.File.new($name_filepath)))"/> + <xsl:if test="$file_exists = 'false'"> <!-- copy attachment content only if file on disk doesnt exist --> + <xsl:value-of select="."/> + </xsl:if> + </xsl:copy> + </xsl:template> + <!-- add @id, mandatory for table auto-layout algorithm --> <xsl:template match="*[local-name() = 'dl' or local-name() = 'table'][not(@id)]" mode="update_xml_step1"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:call-template name="add_id"/> @@ -12442,10 +12468,11 @@ <xsl:when test="normalize-space() != ''"> <pdf:embedded-file xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf" src="{.}" filename="{@name}"/> </xsl:when> <xsl:otherwise> <!-- _{filename}_attachments --> - <xsl:variable name="url" select="concat('url(file:///',$inputxml_basepath, '_', $inputxml_filename_prefix, '_attachments', '/', @name, ')')"/> + <!-- <xsl:variable name="url" select="concat('url(file:///',$inputxml_basepath, '_', $inputxml_filename_prefix, '_attachments', '/', @name, ')')"/> --> + <xsl:variable name="url" select="concat('url(file:///',$inputxml_basepath , @name, ')')"/> <pdf:embedded-file xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf" src="{$url}" filename="{@name}"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> <!-- references to external attachments (no binary-encoded within the Metanorma XML file) --> \ No newline at end of file