views:

121

answers:

1
+1  A: 

Are you looking for something like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  <xsl:param name="currentPage">Sub-sub-foo1</xsl:param>
  <xsl:template match="/">
    Current page: <xsl:value-of select="$currentPage" /><br />
    <ul>
      <xsl:choose>
        <xsl:when test="//menuitem[@name=$currentPage]">
          <xsl:apply-templates select="//menuitem[@name=$currentPage]/.." />
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates />
        </xsl:otherwise>
      </xsl:choose>
    </ul>
  </xsl:template>

  <xsl:template match="menuitem">
    <li>
      <xsl:choose>
        <xsl:when test="@name=$currentPage">
          <b><xsl:value-of select="@name" /></b>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@name" />
        </xsl:otherwise>
      </xsl:choose>

      <xsl:if test="menuitem">
        <ul>
          <xsl:apply-templates />
        </ul>
      </xsl:if>
    </li>
  </xsl:template>

</xsl:stylesheet>
Rubens Farias
The inner ul should be inside the li; the closing li should be put after the closing xsl:if tag.
Jeff Ober
@jeff: ty, fixed
Rubens Farias
Oh. Problem with carrying the variable to the menuitem template.
MrZombie
I get the message that the variable isn't declared.
MrZombie
@MrZombie: did you declared <xsl:param name="currentPage" /> ? You should provide its value before transformation runtime
Rubens Farias
Fixed it somehow, but I couldn't just declare it up front, I do all my transformations in a single go, my XML contains all of the pages, preceded by the menu structure. I probably made some horrible, horrible design mistakes with that work, but still. Getting better, broadening my views, adding to my knowledge... Thanks for the help, man. :)
MrZombie