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

admin2025-04-17  4

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?

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?

Share Improve this question asked Jan 30 at 19:08 NoahNoah 2442 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You are using Antenna House Formatter, so you can use the axf:suppress-duplicate-page-number extension property plus a second fo:page-number-citation to an FO at the end of the range in place of the fo:page-number-citation-last:

<fo:block
    id="a" background-color="lightyellow"
    axf:suppress-duplicate-page-number="true">
  <fo:page-number-citation ref-id="a" />-<fo:page-number-citation ref-id="b" /><fo:inline id="b" />
</fo:block>

The page numbers did not merge for me when I tried <fo:page-number-citation-last ref-id="a" />.

转载请注明原文地址:http://anycun.com/QandA/1744895781a89150.html