Home > Mobile >  Problem of shown/hidden element with if condition in xsl
Problem of shown/hidden element with if condition in xsl

Time:10-25

I want to use if condition in below code.

    <xsl:variable name="vPageNumber"><fo:page-number/></xsl:variable>
    ...
    ..
    .
    <xsl:if test="$vPageNumber==1">
      <fo:block text-align="right" margin-right="24px">
        <fo:external-graphic content-width="20mm"  src="url(D:/Atlassian/images/Turkak.gif)" />
      </fo:block>
   </xsl:if>

Check if current page number is 1, this code block should be shown in header.If not code block should be hidden but it is not working. When we create pdf rendering from below code, Although current page number is 1 Turkak.gif is hidden in all of pages header. The full code is below.

<?xml version="1.0" encoding="ISO-8859-1"?>

#set($maxIssues = 500) ## set an upper limit for issues to be exported
#set($startIssuesOnNewPages = true) ## set to "true" to add a page break before each issue
#set($linkTypeNames = "Relates")    
#set($exportProjectAvatars = true) ## set to "true" to export project avatars for each issue
#set($exportThumbnails = true) ## set to "true" to export thumbnails of the image type attachments
#set($exportChangeHistory = $pdfView.name.contains('All')) ## set to "true" to export the issue field change history
#set($embedAttachments = true) ## set to "true" to include binary file attachments in the PDF document, see: https://www.midori-global.com/products/better-pdf-exporter-for-jira/server/documentation/embedding-attachments
#set($embeddedAttachmentMaxFileSize = 52428800) ## max filesize (bytes) for attachments to be embedded (default: 50M)
#set($hebele = 55555)

$scripting.execute("nfeed-tool.groovy")
$scripting.execute("sub-task-tool.groovy")
$scripting.execute("issue-link-tool.groovy")
$scripting.execute("field-value-tool.groovy")
$scripting.execute("hello-world.groovy")


<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf" font-family="auto">

<fo:layout-master-set >
        <fo:simple-page-master master-name="A4-portrait" page-width="21cm" page-height="29.7cm" margin-top="1cm" 
margin-bottom="1cm" margin-left="1cm" margin-right="1cm">
            <fo:region-body region-name="page-body" margin-top="63mm" margin-bottom="45mm"/>
            <fo:region-before region-name="page-header" extent="60mm" precedence="true"/>
            <fo:region-after region-name="page-footer" extent="45mm" precedence="true"/>
        </fo:simple-page-master>
</fo:layout-master-set>

<fo:declarations>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>$xmlutils.escape($title)</dc:title>
<dc:creator>$xmlutils.escape($user.displayName)</dc:creator>
<dc:description>Issues exported from Jira</dc:description>
<dc:subject>#foreach($issue in $issues)$xmlutils.escape($issue.key)#if($velocityHasNext), #end#end</dc:subject>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>Better PDF Exporter for Jira - https://marketplace.atlassian.com/5167</xmp:CreatorTool>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
#if($embedAttachments)
            #foreach($issue in $issues)
                #foreach($attachment in $issue.attachments)
                    #if($attachment.filesize <= $embeddedAttachmentMaxFileSize)
                        #set($attachmentUrl = "${requestContext.canonicalBaseUrl}/secure/attachment/${attachment.id}/${urlcodec.encode($attachment.filename)}")
                        <pdf:embedded-file filename="${attachment.id}-$xmlutils.escape($attachment.filename)" src="url($attachmentUrl)" description="Attached to [$xmlutils.escape($issue.key)]"/>
                    #end
                #end
            #end
        #end
</fo:declarations>

<fo:bookmark-tree >
#foreach($issue in $issues)
#if($velocityCount <= $maxIssues)
<fo:bookmark internal-destination="$xmlutils.escape($issue.key)" >
<fo:bookmark-title>$xmlutils.escape($issue.key)</fo:bookmark-title>
</fo:bookmark>
#end
#end
</fo:bookmark-tree>

#if($issues && !$issues.empty)
#foreach($issue in $issues)
#if($velocityCount <= $maxIssues)

#if(($velocityCount == 1) || $startIssuesOnNewPages)
<fo:page-sequence master-reference="A4-portrait" id="page-sequence-id">
<xsl:variable name="vPageNumber"><fo:page-number/></xsl:variable>
## header
<fo:static-content flow-name="page-header">
    <fo:table border="solid">
        <fo:table-column column-width="20%"/>
        <fo:table-column column-width="67%"/>
        <fo:table-column column-width="13%"/>
        <fo:table-body>
          
            <fo:table-row >
                <fo:table-cell  >
                  <fo:block text-align="center" margin-left="15px" padding-top="110px">
                      <fo:external-graphic content-width="210px" alignment-baseline="middle"  src="url(D:/Atlassian/images/MANLogo.gif)" />
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell >
                    <fo:block font-size="15pt" text-align="center" margin-top="50px" >MAN TÜRKİYE A.Ş.</fo:block>
                    <fo:block font-size="15pt" text-align="center">Test Laboratuvarı</fo:block>
                    <fo:block font-size="14pt" text-align="center" padding-top="120px">Test Raporu</fo:block>
                    <fo:block font-size="14pt" text-align="center" padding-top="120px"><fo:page-number/></fo:block>
                </fo:table-cell>    
                <fo:table-cell>
                   <fo:block padding-right="15px" padding-bottom="2mm" padding-top="1mm">
                          
                         <xsl:if test="$vPageNumber==1">
                            <fo:block text-align="right" margin-right="24px"   >
                                <fo:external-graphic content-width="20mm"  src="url(D:/Atlassian/images/Turkak.gif)" />
                            </fo:block>
                         </xsl:if>
                        
                       <fo:table width="20mm" height="24mm" font-size="7pt" >
                          <fo:table-body> 
                             <fo:table-row border="solid" height="8mm">
                                  <fo:table-cell>
                                      <fo:block text-align="center" padding="3mm" > 
                                          AB-1365-T
                                      </fo:block>
                                  </fo:table-cell>
                             </fo:table-row>
                             <fo:table-row border="solid" height="8mm" >
                                 <fo:table-cell>
                                      <fo:block text-align="center" padding="3mm">$xmlutils.escape($issue.key)</fo:block>
                                 </fo:table-cell>
                             </fo:table-row>
                             <fo:table-row border="solid" height="8mm" >
                                 <fo:table-cell>
                                      <fo:block text-align="center" padding="3mm"> $date.format("MM-yy", $issue.getCustomFieldValue("customfield_17843"))</fo:block>
                                 </fo:table-cell>
                             </fo:table-row>
                        </fo:table-body>
                      </fo:table>
                  </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</fo:static-content>

## footer
<fo:static-content flow-name="page-footer">
    <fo:block border="solid">
        <fo:table margin="1mm 1mm 1mm 1mm" >    
                <fo:table-column column-width="90%"/>
                <fo:table-column column-width="10%"/>
                    <fo:table-body>
                        <fo:table-row>
                             <fo:table-cell number-columns-spanned="2">
                                <fo:block font-size="80%">1. Bu rapor, laboratuvarın yazılı izni olmadan kısmen kopyalanı çoğaltılamaz.(This report shall not be reproduced other than in full except with the
                                            permission of the laboratory)</fo:block>
                              </fo:table-cell> 
                        </fo:table-row>
                        <fo:table-row>
                             <fo:table-cell number-columns-spanned="2">
                                <fo:block font-size="80%">2. Rapordaki test sonuçları laboratuvara müşteri tarafından teslim edilen ve yukarıda tanımlanan numunelere aittir.(Results in this report refer only to those
                                            samples submitted by the firm mentioned above)</fo:block>
                              </fo:table-cell> 
                               
                        </fo:table-row>
                        <fo:table-row>
                             <fo:table-cell number-columns-spanned="2">
                                <fo:block font-size="80%">3. (*)İşaretli testler akreditasyon kapsamı dışındadır.(Tests marked (*) are outside the scope of accreditation schedule.)</fo:block>
                              </fo:table-cell> 
                        </fo:table-row>
                        <fo:table-row>
                             <fo:table-cell >
                                <fo:block font-size="80%">Aksi belirtilmedikçe ölçüm belirsizliği dikkate alınmadan sonuç bildirilmiştir.</fo:block>
                              </fo:table-cell> 
                               <fo:table-cell >
                                <fo:block font-size="80%">Sayfa <fo:page-number/>/<fo:page-number-citation-last ref-id="page-sequence-id"/></fo:block>
                              </fo:table-cell> 
                        </fo:table-row>
                    </fo:table-body>
        </fo:table>
    </fo:block>
    <fo:block margin-top="2mm">
        <fo:block text-align="center" font-size="85%">FOO</fo:block>
        <fo:block text-align="center" font-size="85%">FOO</fo:block>
        <fo:block text-align="center" font-size="85%">FOO</fo:block>
        <fo:block text-align="center" font-size="85%">FOO</fo:block>
    </fo:block>
</fo:static-content>

#if(($velocityCount == $issues.size()) || ($velocityCount == $maxIssues) || $startIssuesOnNewPages)
</fo:flow>
</fo:page-sequence>
#end
#end
#end
#else
<fo:page-sequence master-reference="A4-landscape">
<fo:flow flow-name="page-body" font-size="9pt">
<fo:block>No issues found</fo:block>
</fo:flow>
</fo:page-sequence>
#end
</fo:root> 

How i can this solve. Thanks in advice.

CodePudding user response:

I think you should investigate how to use fo:page-sequence-master instead; define a "first" page master which uses the header graphic, and a "remaining" page master without the graphic.

e.g. this might get you on the right track https://www.xmlpdf.com/different-first-page.html

  • Related