Noah
Noah

Reputation: 125

How to conditionally insert a value in XSL-FO only if the target page number is different from the current page?

I am working on an XSLT transformation that converts an XML file into an XSL-FO file, which generates a PDF using Antenna House.

In my XSLT, I have a snippet that inserts a value with a page indication (e.g., #A-5#) into the FO output. This value is only relevant if the target page number (referenced by <fo:page-number-citation-last>) differs from the current page number.

<fo:table-cell>
     <fo:block>
        <xsl:text>#</xsl:text>
            <xsl:call-template name="setPage"/>
         <xsl:text>#</xsl:text>
      </fo:block>
</fo:table-cell>

<xsl:template name="setPage">
    <xsl:choose>
        <xsl:when test="ancestor::xpto">
            <xsl:value-of select="@nrb"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="ancestor-or-self::qrew/@pstr"/>
        </xsl:otherwise>
    </xsl:choose>

    <xsl:choose>
        <xsl:when test="ancestor::xpto">N-
            <fo:page-number-citation-last>
                <xsl:attribute name="ref-id"><xsl:value-of select="self::condition/@id"/></xsl:attribute>
            </fo:page-number-citation-last>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="ancestor::block/@blknbr"/>SSZ-
            <fo:page-number-citation-last>
                <xsl:attribute name="ref-id"><xsl:value-of select="self::condition/@id"/></xsl:attribute>
            </fo:page-number-citation-last>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template> 

Currently, I am using post-processing to remove the value if the target page number points to the current page, using the pattern #LETTER-PAGE#.

Is it possible to achieve this result during the XSLT transformation?

Upvotes: 1

Views: 18

Answers (0)

Related Questions