[xsl] Passing params problem.

Subject: [xsl] Passing params problem.
From: Francesco Barresi <kywocs@xxxxxxxxx>
Date: Fri, 29 Apr 2005 13:03:21 -0400
Hi all,
  I have a problem..mm that's strange :-P. The thing is that there's
must be some conceptual error in my xsl because according to what I
know should work just fine, here it goes:

  I have an xml (layouts.xml) like this:

 <div class="menu_2">
     <bbwps:navigationMenu-pagesHere>
     <ul>
         <bbwps:navigationMenu-for-each-page>
             <bbwps:navigationMenu-open>
                 <li>
                     <bbwps:navigationMenu-pageHere/>
                     <ul class="abierto">
                         <bbwps:navigationMenu-childrenHere/>
                     </ul>
                 </li>
             </bbwps:navigationMenu-open>
             <bbwps:navigationMenu-currentpage>
                 <li>
                     <bbwps:navigationMenu-pageHere/>
                     <ul class="descendientes">
                         <bbwps:navigationMenu-childrenHere/>
                     </ul>
                 </li>
             </bbwps:navigationMenu-currentpage>
             <bbwps:navigationMenu-any>
                 <li>
                     <bbwps:navigationMenu-pageHere/>
                 </li>
             </bbwps:navigationMenu-any>
         </bbwps:navigationMenu-for-each-page>
     </ul>
     </bbwps:navigationMenu-pagesHere>
 </div>

  It have some HTML with some "proprietary" tags with the namespace
BBWPS, this is used to make a typical vertical menu in a html page, as
you can see there is a "for-each" (navigationMenu-for-each-page) which
contains the templates for the different types of pages: open,
currentpage, any. This pages are in a xml ($index) with a simple tree
structure which represents the tree structure of the web site.

  The part of the xsl concerning the menu is this:

 <!--PAGES HERE. this acts on the layout-->
     <xsl:template match="bbwps:navigationMenu-pagesHere" mode="layout">
         <xsl:apply-templates select="*" mode="navigationMenu"/>
     </xsl:template>
     <!--HTML. this acts on the layout-->
     <xsl:template match="html:*" mode="navigationMenu">
         <xsl:element name="{local-name()}" >
             <xsl:for-each select="@*">
                 <xsl:attribute name="{local-name()}">
                     <xsl:value-of select="."/>
                 </xsl:attribute>
             </xsl:for-each>
             <xsl:if test="./child::node()">
                 <xsl:apply-templates mode="navigationMenu"/>
             </xsl:if>
         </xsl:element>
     </xsl:template>
     <!--FOR EACH PAGE. this acts on the layout-->
     <xsl:template match="bbwps:navigationMenu-for-each-page"
mode="navigationMenu">
         <xsl:apply-templates
select="$index/ancestor-or-self::*[@subhome='true'][1]/child"
mode="navigationMenu">
             <xsl:with-param name="templates" select="."/>
         </xsl:apply-templates>
     </xsl:template>
     <!--OPEN PAGE. this acts on the index-->
     <xsl:template match="child[@open='true']" mode="navigationMenu">
         <xsl:param name="templates"/>
         <xsl:apply-templates
select="$templates//bbwps:navigationMenu-open" mode="navigationMenu">
             <xsl:with-param name="currentpage" select="."/>
         </xsl:apply-templates>
     </xsl:template>
     <!--CURRENT PAGE. this acts on the index-->
     <xsl:template match="child[@currentpage='true']" mode="navigationMenu">
         <xsl:param name="templates"/>
         <xsl:apply-templates
select="$templates//bbwps:navigationMenu-currentpage"
mode="navigationMenu">
             <xsl:with-param name="currentpage" select="."/>
         </xsl:apply-templates>
     </xsl:template>
     <!--ANY PAGE. this acts on the index-->
     <xsl:template match="child" mode="navigationMenu">
         <xsl:param name="templates"/>
         <xsl:apply-templates
select="$templates//bbwps:navigationMenu-any" mode="navigationMenu">
             <xsl:with-param name="currentpage" select="."/>
         </xsl:apply-templates>
     </xsl:template>
     <!--CHILDREN HERE. this acts on the layout-->
     <xsl:template match="bbwps:navigationMenu-childrenHere"
mode="navigationMenu">
         <xsl:param name="currentpage"/>
         <xsl:param name="templates"/>
         <xsl:apply-templates select="$currentpage/child"
mode="navigationMenu">
             <xsl:with-param name="templates" select="$templates"/>
         </xsl:apply-templates>
     </xsl:template>
     <!--PAGE HERE. this acts on the layout-->
     <xsl:template match="bbwps:navigationMenu-pageHere"
mode="navigationMenu">
         <xsl:param name="currentpage"/>
         <xsl:choose>
             <xsl:when test="$currentpage/@type='external-link'">
                 <xsl:call-template name="crea-link">
                     <xsl:with-param name="tipo" select="'http'"/>
                     <xsl:with-param name="url" select="$currentpage/url"/>
                     <xsl:with-param name="cont" select="$currentpage/nome"/>
                 </xsl:call-template>
             </xsl:when>
             <xsl:otherwise>
                 <xsl:call-template name="crea-link">
                     <xsl:with-param name="tipo" select="'idpagina'"/>
                     <xsl:with-param name="url"
select="$currentpage/id_inter"/>
                     <xsl:with-param name="cont" select="$currentpage/nome"/>
                 </xsl:call-template>
             </xsl:otherwise>
         </xsl:choose>
     </xsl:template>

 This doesn't work, what I get is this:

 [...]
 <div class="menu_2">
 <ul>
 [..]

  This is because the $currentpage param that is generated in the
CHILD templates doesn't work properly. CHILD is a really stupid name
that i used in the xml, is a tag not the "child::". The CHILD
templates work on the $index and when I set the select attribute on
with-param like this: select="." I get an empty $currentpage on the
tags like <bbwps:navigationMenu-pageHere/> wich are inside some HTML
tags.

  <xsl:template match="child" mode="navigationMenu">
           <xsl:param name="templates"/>
         <xsl:apply-templates
select="$templates//bbwps:navigationMenu-any" mode="navigationMenu">
               <!-- HERE IS THE PROBLEM -->
               <xsl:with-param name="currentpage" select="."/>
           </xsl:apply-templates>
     </xsl:template>

  Debugging the xsl in the CHILD templates the context node is correct
but when I use select="." I get an empty param.

  The real problem I think that is that the param $currentpage never
gets to <bbwps:navigationMenu-pageHere/> because is inside some HTML,
is this true? or the param buble down the parsed XML all the way?

 Any tip is welcome.

 Thanks
 Bye
 Francesco.

--
www.GetFirefox.com !!
http://kywocs.blogspot.com

Current Thread