[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Process Children Before Parents Recursively!

Subject: Process Children Before Parents Recursively!
From: "Adam J Knight" <adam@xxxxxxxxxxxxxxxxx>
Date: Mon, 18 Jul 2005 17:26:49 +1000
addmenuitem call function
Hi all,

With the following xml structure:

-<dfile>
  - <df_data_row>
      <document_id>13</document_id>
      <name>About Us</name>
      <parent>0</parent>
      - <df_data_row>
        <document_id>57</document_id>
        <name>About Sub 1</name>
        <parent>13</parent>
        - <df_data_row>
            <document_id>58</document_id>
            <name>About Sub Sub 1</name>
            <parent>57</parent>
          </df_data_row>
      </df_data_row>
    </df_data_row>
  </dfile>

And this xslt stylesheet:

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

  <xsl:param name="url"/>
  <xsl:output method="html" encoding="ISO-8859-1"/>

  <xsl:template match="/">
  <script language="javascript">
    function loadMenus() {
      <xsl:for-each select="//df_data_row">
	  <xsl:if test="child::df_data_row">
	    <xsl:call-template name="sub_menus"/>
	  </xsl:if>
	</xsl:for-each>
	writeMenus();
    }
  </script>
  <script language="JavaScript">loadMenus();</script>
  </xsl:template>

  <xsl:template name="sub_menus">
  window.mnu_<xsl:value-of select="document_id"/> = new Menu('<xsl:value-of
select="name"/>','Verdana, Arial, Helvetica,
sans-serif',11,'ffffff','000033','cce3f8','ffffff','left','top',2,2,300,2,1,
true,true,true,0);

    <xsl:call-template name="menu_items"/>
  </xsl:template>



<xsl:template name="menu_items">
  <xsl:for-each select="child::df_data_row">
    <xsl:choose>
	<xsl:when test="child::df_data_row">
	  mnu_<xsl:value-of
select="parent::df_data_row/document_id"/>.addMenuItem(mnu_<xsl:value-of
select="document_id"/>,"document.location.href='index.php?pg=<xsl:value-of
select="document_id"/>'");
	</xsl:when>
	<xsl:otherwise>
	  mnu_<xsl:value-of
         select="parent::df_data_row/document_id"/>.addMenuItem("<xsl:value-

         of select="name"/>", "document.location.href='index.php?pg=
         <xsl:value-of select="document_id"/>'" );
	</xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

I am generating these results:

<script language="javascript">
  function loadMenus() {

    window.mnu_13 = new Menu('About Us','Verdana, Arial, Helvetica,
sans-serif',11,'ffffff','000033','cce3f8','ffffff','left','top',2,2,300,2,1,
true,true,true,0);

mnu_13.addMenuItem(mnu_57,"document.location.href='index.php?pg=57'");

window.mnu_57 = new Menu('About Sub 1','Verdana, Arial, Helvetica,
sans-serif',11,'ffffff','000033','cce3f8','ffffff','left','top',2,2,300,2,1,
true,true,true,0);

mnu_57.addMenuItem("About Sub Sub 1", "document.location.href='
index.php?pg=58'");

writeMenus();
}

For those who know JavaScript ('eeek!!!') you notice a problem.

Because the style sheet processes from outside nodes to inner nodes,
references to child menus are being outputted before the menu itself is
being generated ('ie: mnu_57), creating errors.

I would really appreciate if some one can demonstrate how I would alter the
logic of this style sheet, so that all child menus are generated before
their parents (recursively). Thus I should be error free.

I would appreciate any help!!!!!!!!!!

Cheers,
Adam
 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.