Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2006, 05:10 PM
Registered User
 
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default trying to assign a parameter value to 'match='

Hi all. I'm hoping someone can help. I get an error message, " NodeTest expected here. USAGE-LOG-2.0/-->$<--command " , when trying to use a parameter value on a 'match=' keyword within the xsl:key statement.

like this....
<xsl:param name="command"/>
<xsl:key name="gis" match="USAGE-LOG-2.0/$command" use="U"/>

What I'm passing in is a specific node name that I wish to use as my key. Can it be done?

Thanks,
John



 
Old April 1st, 2006, 03:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Two issues here. Firstly, variables in XSLT aren't macros: they represent values, not bits of expression text. If you want to test a variable name in a path expression, you can't write a/$b, you have to write a/*[name()=$b]. Secondly, though, in XSLT 1.0 there's a specific ban on using variables in the match pattern of a key. This is to prevent circularities where the variable depends on the key and the key depends on the variable.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 1st, 2006, 10:03 PM
Registered User
 
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike!

Here is what I'm trying to do.....I have various element names and I'm passing in a param for a unique element name that I wish to gather the rest of the xml data for.

Here is my XSL. I thought I could pass the param and assign it in the match= parameter but that appears to be a violation. I'm attempting to get a list of unique "U"sers that ran a SEARCH command. Various commands are contained in my XML data in which the command is actually an element node. I can't seem to figure out how to limit it to just the element name that I'm passing in. My goal was to have the highlighted statement read...match="USAGE-LOG-2.0/SEARCH".

<xsl:param name="command"/>
<xsl:key name="gis" match="USAGE-LOG-2.0/*" use="U"/>
<xsl:template match="node()">
<xsl:call-template name="Style"/>

<table>
<xsl:for-each select="//*[generate-id(.)=generate-id(key('gis',U)[1])]">
<xsl:sort select="U"/>

<tr><td>
<a target="details">
<xsl:attribute name="href">
<xsl:value-of select="concat('arc_log.asp?user=',U)" />
</xsl:attribute>
<xsl:value-of select="U" />
</a>
</td>
<td><xsl:value-of select="count(key('gis', U))" />
</td>
<td>
    <xsl:variable name="response">
    <xsl:for-each select="key('gis',U)">
            <accum>
                 <xsl:value-of select="vbs:vbDateDiff(string(T/@ts),string(T/@te))"/>
            </accum>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="sum(msxsl:node-set($response)/accum)"/>
</td>
</tr>
</xsl:for-each>

</table>

</xsl:template>
</xsl:stylesheet>
 
Old April 3rd, 2006, 10:18 AM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

Possible Suggestions:
1. for the key, use="concat(name(),U)"

2. use not following:: axis to determine uniqueness instead of key.
something like for-each //USAGE-LOG-2.0/*
<xsl:if test="not (following::*[(../name()='USAGE-LOG-2.0') and (name()=current()/name()) and (U=current()/U))]">

Don't know if either will work with what you're trying to do.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter object malfunction - out parameter dash dev C# 2005 6 December 4th, 2007 12:58 PM
Can you Assign a Collection to a Property? MandMD2 Beginning VB 6 2 May 3rd, 2007 05:24 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Pull and Assign XSLT Parameter from ASPX Doc kwilliams ASP.NET 2.0 Basics 0 October 20th, 2006 11:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.