1

Here is my XSLT:

<xsl:choose>  
  <xsl:when test="string-length(/*/location/name)">
    <xsl:variable name="pagurl">/location/<xsl:value-of select="/*/location/@id" />comments</xsl:variable>
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name="pagurl">/state/<xsl:value-of select="/*/state/@code" />/comments</xsl:variable>
  </xsl:otherwise>
</xsl:choose>

<div class="pagination_outer" id="pager">
  <xsl:call-template name="pagination">
    <xsl:with-param name="url"><xsl:value-of select="$pagurl"/></xsl:with-param>                                
  </xsl:call-template>
</div>

I am doing the following:

  1. Assigning a variable $pagurl to a value based on a string length.
  2. Trying to use the variable inside the call <xsl:with-param name="url"><xsl:value-of select="$pagurl"/></xsl:with-param>

When I include this call the page never seems to finish loading however when I do not use it the page loads just fine. I imagine there's an error in my usage of this.

I do not think it's necessary to see the pagination template as it works fine if I hardcode a value.

Suggestions?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
slicks1
  • 349
  • 1
  • 13
  • Looks like you're trying to [execute dynamic XPath](http://stackoverflow.com/questions/4630023/dynamic-xpath-in-xslt)? – har07 Mar 03 '16 at 03:26
  • 1
    @har07, no, it's nothing that sophisticated -- just a [scoping issue](http://stackoverflow.com/a/35763135/290085). – kjhughes Mar 03 '16 at 04:29

1 Answers1

0

The variable, pageurl, defined within xsl:when and (again) within xsl:otherwise, is out of scope by the time you try to use it as a parameter to pagination. You say the page never seems to finish loading, but I suspect that you're missing an error message.

Try this instead:

<xsl:variable name="pagurl">
  <xsl:choose>  
    <xsl:when test="string-length(/*/location/name)">
      <xsl:text>/location/</xsl:text>
      <xsl:value-of select="/*/location/@id"/>
      <xsl:text>comments</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>/state/</xsl:text>
      <xsl:value-of select="/*/state/@code"/>
      <xsl:text>/comments</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

<div class="pagination_outer" id="pager">
  <xsl:call-template name="pagination">
    <xsl:with-param name="url" select="$pagurl"/>
  </xsl:call-template>
</div>
kjhughes
  • 106,133
  • 27
  • 181
  • 240