471,594 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 1308

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stan Huff | last post: by
8 posts views Thread by David Duerrenmatt | last post: by
3 posts views Thread by paapa21 | last post: by
6 posts views Thread by daveyand | last post: by
reply views Thread by leo001 | last post: by

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.