Unable to update variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin

    Unable to update variable

    I am having difficulty updating a variable page-time-stamp in the
    following snippit. The variable time-stamp is initialized from the
    attribute time-stamp from the log element. Some of the page elements
    (children of log) in my XML source have a time-stamp attribute, so I
    want to use the time-stamp from the page for the page-time-stamp
    value. I use an xsl:choose/xsl:when/xsl:otherwise combination to setup
    an if/else statement to select the page-time-stamp value. When I run
    this template, the page-time-stamp value never changes. I only
    displays the initial time-stamp value from the log element. Can anyone
    help me?

    Kevin

    <xsl:template match="log">

    <xsl:variable name="applicati on-name" select="@applic ation-name"/>
    <xsl:variable name="applicati on-version" select="@applic ation-
    version"/>
    <xsl:variable name="time-stamp" select="@time-stamp"/>

    <xsl:variable name="applicati on-string">
    <xsl:value-of select="$applic ation-name"/><xsl:textv</
    xsl:text><xsl:v alue-of select="$applic ation-version"/>
    </xsl:variable>

    <fo:root>

    <fo:layout-master-set>
    <fo:simple-page-master master-name="standard-page" page-
    height="8.5in" page-width="11.0in" margin-top="0.5in" margin-
    bottom="0.5in" margin-left="0.5in" margin-right="0.5in">
    <fo:region-body region-name="xsl-region-body" margin-top="0.25in"/
    >
    <fo:region-before region-name="xsl-region-before" extent="0.25in"/
    >
    </fo:simple-page-master>
    </fo:layout-master-set>

    <xsl:for-each select="page">

    <xsl:variable name="page-number" select="positio n()"/>

    <xsl:choose>
    <xsl:when test="@time-stamp">
    <xsl:variable name="page-time-stamp" select="@time-stamp"/>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:variable name="page-time-stamp" select="$time-stamp"/>
    </xsl:otherwise>
    </xsl:choose>

    <fo:page-sequence master-reference="stan dard-page">

    <xsl:if test="$page-number &gt; 1">
    <fo:static-content flow-name="xsl-region-before">
    <fo:table font-family="Helveti ca, sans-serif" font-
    size="8pt" inline-progression-dimension="100% " table-layout="fixed">
    <fo:table-body>
    <fo:table-row>
    <fo:table-cell text-align="left">
    <fo:block><xsl: value-of
    select="$applic ation-string"/></fo:block>
    </fo:table-cell>
    <fo:table-cell text-align="center">
    <fo:block><xsl: value-of select="$page-
    time-stamp"/></fo:block>
    </fo:table-cell>
    <fo:table-cell text-align="right">
    <fo:block>Pag e <xsl:value-of
    select="$page-number"/>
    </fo:block>
    </fo:table-cell>
    </fo:table-row>
    </fo:table-body>
    </fo:table>
    </fo:static-content>
    </xsl:if>
  • Kevin

    #2
    Re: Unable to update variable

    On Jun 3, 11:35 am, Kevin <Kevin.S.Par... @alumni.utexas. netwrote:
    I am having difficulty updating a variable page-time-stamp in the
    following snippit. The variable time-stamp is initialized from the
    attribute time-stamp from the log element. Some of the page elements
    (children of log) in my XML source have a time-stamp attribute, so I
    want to use the time-stamp from the page for the page-time-stamp
    value. I use an xsl:choose/xsl:when/xsl:otherwise combination to setup
    an if/else statement to select the page-time-stamp value. When I run
    this template, the page-time-stamp value never changes. I only
    displays the initial time-stamp value from the log element. Can anyone
    help me?
    >
    Kevin
    >
    <xsl:template match="log">
    >
    <xsl:variable name="applicati on-name" select="@applic ation-name"/>
    <xsl:variable name="applicati on-version" select="@applic ation-
    version"/>
    <xsl:variable name="time-stamp" select="@time-stamp"/>
    >
    <xsl:variable name="applicati on-string">
    <xsl:value-of select="$applic ation-name"/><xsl:textv</
    xsl:text><xsl:v alue-of select="$applic ation-version"/>
    </xsl:variable>
    >
    <fo:root>
    >
    <fo:layout-master-set>
    <fo:simple-page-master master-name="standard-page" page-
    height="8.5in" page-width="11.0in" margin-top="0.5in" margin-
    bottom="0.5in" margin-left="0.5in" margin-right="0.5in">
    <fo:region-body region-name="xsl-region-body" margin-top="0.25in"/
    >
    <fo:region-before region-name="xsl-region-before" extent="0.25in"/
    >
    </fo:simple-page-master>
    </fo:layout-master-set>
    >
    <xsl:for-each select="page">
    >
    <xsl:variable name="page-number" select="positio n()"/>
    >
    <xsl:choose>
    <xsl:when test="@time-stamp">
    <xsl:variable name="page-time-stamp" select="@time-stamp"/>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:variable name="page-time-stamp" select="$time-stamp"/>
    </xsl:otherwise>
    </xsl:choose>
    >
    <fo:page-sequence master-reference="stan dard-page">
    >
    <xsl:if test="$page-number &gt; 1">
    <fo:static-content flow-name="xsl-region-before">
    <fo:table font-family="Helveti ca, sans-serif" font-
    size="8pt" inline-progression-dimension="100% " table-layout="fixed">
    <fo:table-body>
    <fo:table-row>
    <fo:table-cell text-align="left">
    <fo:block><xsl: value-of
    select="$applic ation-string"/></fo:block>
    </fo:table-cell>
    <fo:table-cell text-align="center">
    <fo:block><xsl: value-of select="$page-
    time-stamp"/></fo:block>
    </fo:table-cell>
    <fo:table-cell text-align="right">
    <fo:block>Pag e <xsl:value-of
    select="$page-number"/>
    </fo:block>
    </fo:table-cell>
    </fo:table-row>
    </fo:table-body>
    </fo:table>
    </fo:static-content>
    </xsl:if>
    I figured it out. I needed to restructure the variable definition of
    page-time-stamp.


    <xsl:variable name="page-time-stamp">
    <xsl:choose>
    <xsl:when test="@time-stamp">
    <xsl:value-of select="@time-stamp"/>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:value-of select="$time-stamp"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    Comment

    • Joseph J. Kesselman

      #3
      Re: Unable to update variable

      Kevin wrote:
      I figured it out. I needed to restructure the variable definition of
      page-time-stamp.
      Exactly. XSLT variables are single-assignment and their scope is limited
      to the descendants of their parent element. To use conditionals when
      setting a variable, you have to make the value conditional, not the
      assignment.

      Comment

      Working...