Dynamically change page header in XSLT

2019-03-06 02:08发布

问题:

Dynamic change of page header in XSLT

I want same Image to be in Header however the content over image should change dynamically according to value in XML node

<fo:flow flow-name="header">
  <fo:table>
     <fo:table-body>
          <fo:table-cell border="0pt">
            <fo:block>
               <fo:external-graphic ID="headerlogo" src="url('imgae_url')" content-width="50%" content-height="50%">
                <fo:table-cell border="0pt">
                  <fo:block margin-top="1.5cm" margin-right="1.2cm" text-align="left" >
                    <fo:inline font-size="30pt" color="white" >
                      <xsl:value-of select="path_url"/>
                    </fo:inline>
                  </fo:block>
                </fo:table-cell>
              </fo:external-graphic>
            </fo:block>
          </fo:table-cell>
         </fo:table-body>
      </fo:table>
    </fo:flow>

回答1:

As @potame already mentioned in comments, <fo:marker> and <fo:retrieve-marker> are designed specially for this. Since you don't give any xml I created a simple example to show how to retrieve the marker and the logic behind it then you should be able to adapt to your code.

<fo:flow flow_name="xsl-region-before">
    <fo:table table-layout="fixed" width="100%">
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell>
                    <fo:block>
                        <!-- Retrieve the marker value -->
                        <fo:retrieve-marker retrieve-class-name="header_value"/>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</fo:flow>

Then somewhere in your code (probably in the region-body you will set the marker value (In your case it would be a path url if I understand your question) depending on your wanted condition. Something like :

<xsl:when test="condition">
    <fo:marker marker-class-name="header_value"/>
        <xsl:value-of select="path_url"/>
    </fo:marker>
</xsl:when>
<xsl:when test="condition2">
    <fo:marker marker-class-name="header_value"/>
        <xsl:value-of select="path_url2"/>
    </fo:marker>
</xsl:when>


标签: xml xslt xsl-fo