1
votes
<!-- Get the url of a node based on a list of positions (starting point = language root) -->
<xsl:template name="getUrl">
  <xsl:param name="id" />
  <xsl:param name="positions" />
  <xsl:param name="i" select="0" />
  <xsl:param name="max" />

  <!-- Return the url -->
  <xsl:if test="$i = $max">    
    <xsl:value-of select="umbraco.library:NiceUrl($id)" />    
  </xsl:if>

  <xsl:if test="$i &lt; $max">
    <xsl:call-template name="getUrl">
      <xsl:with-param name="id">
        <!-- Define the id of the next item in the tree structure -->
        <xsl:for-each select="//* [@id = $id]/child::* [@isDoc]">
          <xsl:if test="position() = number(umbraco.library:Split($positions, ',')/value[number($i)])">  
            <xsl:value-of select="@id" />
          </xsl:if>
        </xsl:for-each>
      </xsl:with-param>
      <xsl:with-param name="positions">
        <xsl:value-of select="$positions"/>
      </xsl:with-param>
      <xsl:with-param name="i">
        <xsl:value-of select="$i + 1"/>
      </xsl:with-param>
      <xsl:with-param name="max">
        <xsl:value-of select="$max"/>
      </xsl:with-param>    
    </xsl:call-template>
  </xsl:if>  
</xsl:template>

I am using a macro with XLST file. When using this code, I get an error (Value was either too large or too small for an Int32). The error occurs on these two lines:

<xsl:value-of select="umbraco.library:NiceUrl($id)" /> 
<xsl:call-template name="getUrl">

Can someone tell me what I'm doing wrong here, becuase this XSLT file works fine on every page, except for new pages I create.

1

1 Answers

1
votes

Ok I found a solution: I added an extra check to this part:

<!-- Return the url -->
<xsl:if test="$i = $max"> 
  <xsl:if test="$id != '' ">  
    <xsl:value-of select="umbraco.library:NiceUrl($id)" />    
  </xsl:if>
</xsl:if>

this fixed my problem.