Re: Passing Variable into an external xml document template

Subject: Re: Passing Variable into an external xml document template
From: "Sia Rahimi" <sia_rahimi@xxxxxxxxxxx>
Date: Thu, 17 Aug 2000 00:00:20 GMT
BTW, although my problem is solved, I am curiuos why
Method1 doesn't work but Method2 works.  Can anybody explain this, please?

Method1:
<xsl:apply-templates select="document('Menus.xml')/MenuTreeList">
 <xsl:with-param name="theMenu" select="MenuName"/>
</xsl:apply-templates>

Method2:
<xsl:variable name="myMenu">
 <xsl:value-of select="MenuName"/>
</xsl:variable>
<xsl:apply-templates select="document('Menus.xml')/MenuTreeList">
 <xsl:with-param name="theMenu" select="$myMenu"/>
</xsl:apply-templates>

Thanks,
Sia.


From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxx
Subject: Re: Passing Variable into an external xml document template
Date: Wed, 16 Aug 2000 14:24:54 -0700

Sia --

document('Menus.xml') in your apply-templates returns the root node of
the Menus.xml document.  This is then used for the apply-templates.
Since you do not have a rule matching the root node, the built-in root
node rule is used.  This invokes apply-templates for each child of the
root.  In this case, that's the MenuTreeList template.  However, since
this is invoked from the built-in rule, no parameters are passed.

Change your select to document('Menus.xml')/MenuTreeList and everything
should work as you want.

Also, you'll need a closing quote after theMenu in:

<xsl:with-param name="theMenu select="MenuName"/>

HTH,
Gary


Sia Rahimi wrote: > > Hi, > > Known: > (1) How to pass parameters to a template > (2) How to use an an external xml file > > Problem: > Within the template of an external xml file, > I want to process based on the parameter Passed in. > > XML main: > <MenuDisplay> > <MenuName>Main</MenuName> > </MenuDisplay> > > XML external (Menus.xml): > <MenuTreeList> > <MenuTree name="Login"> > <MenuItem> > <Text>Please Login</Text> > </MenuItem> > </MenuTree> > <MenuTree name="Main"> > <MenuItem> > <Text>System News</Text> > </MenuItem> > <MenuItem> > <Text>Customer Menu</Text> > </MenuItem> > </MenuTree> > </MenuTreeList> > > XSL: > <xsl:stylesheet > version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform";> > <xsl:template match="MenuDisplay"> > <xsl:apply-templates select="document('Menus.xml')"> > <xsl:with-param name="theMenu select="MenuName"/> > </xsl:apply-templates> > </xsl:template> > <xsl:template match="MenuTreeList"> > <xsl:param name="theMenu"/> > <xsl:apply-templates select="MenuTree[@name=$theMenu]"/> > </xsl:template> > </xsl:stylesheet> > > It seems that the parameter theMenu is not set. > > Thanks to Jeni's site I have come this far, but, although > the current problem seems like another problem answered by Jeni > "Re:Loading an external file of index" it does not seem to > work for me. (using xalan). > > Thanks for any help you may be able to provide.


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread