473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need help understanding PARAMs

I eventually want to pass a variable to my XSLT file, but, for now, I'm just
trying to be able to declare it globally in the XSLT file itself.

So, I added this to the top of the page:

<xsl:param name="currentPage">5</xsl:param>

BTW, this is a menu I'm creating and, as such, need to know what node it the
'current page' the site/menu is on.

So, elsewhere in my XSLT file, where I want to see if the link I'm
generating matches the current page so I can give it a different class, I
use this:

<xsl:when test="contentID=$currentPage">

This works.

However, I'm trying to establish the current node from the get go using the
match attribut of the xml:template:

<xsl:template match="*[contentID=5]">

This finds the item with the contentID=5

If I try to bring in the parameter like this:

<xsl:template match="*[contentID=$currentPage]">

I get a "Variables may not be used within this expression.
*[contentID=-->$currentPage<--]" error.

Is this just a syntax error on my part, or can I not do what I'm trying to
do?

-Darrel
Nov 12 '05 #1
2 1355

"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I eventually want to pass a variable to my XSLT file, but, for now, I'm just trying to be able to declare it globally in the XSLT file itself.

So, I added this to the top of the page:

<xsl:param name="currentPage">5</xsl:param>

BTW, this is a menu I'm creating and, as such, need to know what node it the 'current page' the site/menu is on.

So, elsewhere in my XSLT file, where I want to see if the link I'm
generating matches the current page so I can give it a different class, I
use this:

<xsl:when test="contentID=$currentPage">

This works.

However, I'm trying to establish the current node from the get go using the match attribut of the xml:template:

<xsl:template match="*[contentID=5]">

This finds the item with the contentID=5

If I try to bring in the parameter like this:

<xsl:template match="*[contentID=$currentPage]">

I get a "Variables may not be used within this expression.
*[contentID=-->$currentPage<--]" error.

Is this just a syntax error on my part, or can I not do what I'm trying to
do?
In XSLT 1.0 it is illegal to have an xsl:variable reference within a match
pattern, because this may lead to a circular definition.

One workaround is the following:

<xsl:template match="*[contentID]">
<xsl:if test="contentID = $currentPage">

<!-- Put all processing here -->
</xsl:if>
</xsl:template>
BTW, it is more straightforward to write:
<xsl:param name="currentPage" select="5">

than
<xsl:param name="currentPage">5</xsl:param>

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Nov 12 '05 #2
> One workaround is the following:
<xsl:template match="*[contentID]">
<xsl:if test="contentID = $currentPage">
<!-- Put all processing here -->
</xsl:if>
</xsl:template>


Hmm...that doesn't work for me (thought that could be due to other problems
with my logic).

I want the initial template to match a very specific node, so I can then
navigate up and down relatively from that particular node.

The if doesn't quite seem to do the same thing as a template match (in my
head, at least).

So, I suppose the problem is with my match and i need to rethink how to do
this with the if.

If it helps, here's what I have now (It's MESSY, though and not fully
thought out)

================================================== =============

<xsl:param name="currentPage">5</xsl:param>

<xsl:template match="*[contentID=5]">
<!-- this is the CURRENT PAGE node: -->
<xsl:if test="../../page">
PARENT(S):
<ul>
<xsl:for-each select="../../page">
<li><a href="{linkURL}"><xsl:value-of select="linkTitle"/></a></li>
</xsl:for-each>
</ul>
</xsl:if>
<!-- this is the SIBLING node(s): -->
<xsl:if test="../page">

SIBLING(S):
<ul>
<xsl:for-each select="../page">
<xsl:choose>
<xsl:when test="contentID=$currentPage">
<li>CURRENT PAGE <xsl:value-of select="linkTitle" /><br />

<!-- does node have children? to find out check for page element -->
<xsl:if test="page">
CHILDREN:
<ul>
<xsl:for-each select="page">
<li><xsl:value-of select="linkURL"/><xsl:value-of
select="linkTitle"/></li>
</xsl:for-each>
</ul>
</xsl:if>

</li>
</xsl:when>
<xsl:otherwise>
<li>SIBLING PAGE <xsl:value-of select="linkTitle" /><br /></li>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</ul>

</xsl:if>

</xsl:template>

================================================== ==============

-Darrel
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mihaly | last post by:
Hello, i'm using a VC++ com+ object, it's reference in vs .net, this com object have a function that have to params, the interop com object recive Object Params and the original com object say...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
3
by: Stan Huff | last post by:
Is there any way to disable the "params" on a particular invocation so that one can pass an array containing the arguments and not have receiver get an array having you argument array stuffed into...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
8
by: David Duerrenmatt | last post by:
Hi there For some reasons, I've to use Python 1.5.2 and am looking for a workaround: In newer Python versions, I can call a function this way: func = some_function func(*params) Then,...
3
by: paapa21 | last post by:
I have two datalist in two panel (viewdatalistpanel and updateDatalist). One datalist bring all student details from the database and the other update the student details in the database. On page...
9
by: Mickey Segal | last post by:
The long-simmering Eolas patent dispute: http://www.microsoft.com/presspass/press/2003/oct03/10-06EOLASPR.mspx has led to an optional Microsoft Update: http://support.microsoft.com/kb/912945/en-us...
6
by: daveyand | last post by:
Hey Guys, I've stumped. I created a function that does various things to select boxes. Namely Get All selected indexes, populate array with these values
2
by: FFMG | last post by:
Hi, I was looking at http://www.php.net/manual/en/function.call-user-func-array.php and I was wondering... Given, // -- function foo( &$params) {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.