Search

$current-node/@id = $test-id will be true even though
<xsl:value-of select="concat( $current-node/@id, ' = ', $test-id, ' = ' )" /><xsl:value-of select="$current-node/@id = $test-id" /> will output 3 = 4 = true

What I’m attempting to do here is look at the @id of a given page element and see if it matches with $test-id. If it doesn’t and the page element has a parent page node we recurse substituting the parent for the $current-node.

Here’s the code as it stands right now…

<xsl:template name="page-in-lineage">
  <xsl:param name="test-id" select="''" />
  <xsl:param name="ancestor-id" select="''" />
  <xsl:param name="current-node" select="//page[@id = $ancestor-id]" />
  <xsl:param name="parent-node" select="//page[@id = $ancestor-id]/../../page" />

  <p><xsl:value-of select="concat( $current-node/@id, ' = ', $test-id, ' = ' )" /><xsl:value-of select="$current-node/@id = $test-id" /></p>

  <xsl:choose>
    <xsl:when test="$current-node/@id = $test-id">yes, even though <xsl:value-of select="concat( $current-node/@id, ' = ', $test-id, ' = ' )" /><xsl:value-of select="$current-node/@id = $test-id" /></xsl:when>
    <xsl:otherwise>
      <xsl:if test="$parent-node">
        <xsl:call-template name="page-in-lineage">
          <xsl:with-param name="ancestor-id" select="$parent-node/@id" />
          <xsl:with-param name="test-id" select="$test-id" />
        </xsl:call-template>
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

Err… here, I fixed it:

<xsl:template name="page-in-lineage">
  <xsl:param name="test-id" select="''" />
  <xsl:param name="ancestor-id" select="''" />
  <xsl:param name="current-node" select="//page[@id = $ancestor-id]" />
  <xsl:param name="parent-node" select="$current-node/parent::page" />

  <xsl:choose>
    <xsl:when test="$current-node/@id = $test-id">yes</xsl:when>
    <xsl:otherwise>
      <xsl:if test="$parent-node">
        <xsl:call-template name="page-in-lineage">
          <xsl:with-param name="ancestor-id" select="$parent-node/@id" />
          <xsl:with-param name="test-id" select="$test-id" />
        </xsl:call-template>
      </xsl:if>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details