p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 2nd, 2009, 04:02 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default xsl:variable question

I am trying to use xsl:variable to clean up my code a bit, but I can't quite get it to work how I want it to.

The code is pretty ugly due to huge xPath expressions (main reason I want to use variables) so I'll just show you the code with the long paths changed to short ones.

I am looking for a more concise way to get the functionality of this code:
Code:
<xsl:if text="count(foo2/bar2[foo/bar = 'CNTY1' or foo/bar = 'CNTY2']) = 0">
    <!-- code here -->
</xsl:if>
Code:
<xsl:variable name="countyPath" select="'foo/bar'" /> 

<xsl:variable name="allCountyPath" select="$countyPath = 'CNTY1' or $countyPath = 'CNTY2'/>

.
.
.

<xsl:if test="count(foo2/bar2[allCountyPath]) = 0">
    <!-- code here -->
</xsl:if>
I've tried removing the inner single quotes from the select attribute on the countyPath variable but it doesn't seem to help. Even though there are counties there, it seems to return 0.

Any ideas on where to go from here?

Edit:Sorry for the generic title, was going to try to make it more descriptive but I can't seem to edit it.

Thanks!

John

Last edited by tieme : July 2nd, 2009 at 04:06 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2009, 05:02 AM
mhkay's Avatar
Wrox Author
Points: 12,642, Level: 48
Points: 12,642, Level: 48 Points: 12,642, Level: 48 Points: 12,642, Level: 48
Activity: 97%
Activity: 97% Activity: 97% Activity: 97%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 Posts
Default

First get rid of the inner quotes.

A variable holds a value (in this case, a set of nodes), it doesn't hold a path expression. When you write <xsl:variable name="x" select="foo/bar"/>, it evaluates foo/bar in the current context to return a set of nodes. You seem to be under the incorrect impression that the value of the variable will be a path expression that is evaluated in the context where it is used.

In XSLT 2.0, you can write f/b[foo/bar = ('C1', 'C2')]. In XSLT 1.0, you can write f/b[foo/bar[. = 'C1' or . = 'C2']].
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
tieme (July 2nd, 2009)
  #3 (permalink)  
Old July 2nd, 2009, 05:35 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Michael,

Thanks for the help! It is exactly the information I was looking for. In my defense, the W3Schools page does not indicate that xsl:variable is generally used to hold a set of nodes, and their only example uses it to hold a string (hence the inner quotes). I think I need to purchase your book...

John
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 2nd, 2009, 05:43 AM
mhkay's Avatar
Wrox Author
Points: 12,642, Level: 48
Points: 12,642, Level: 48 Points: 12,642, Level: 48 Points: 12,642, Level: 48
Activity: 97%
Activity: 97% Activity: 97% Activity: 97%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 Posts
Default

I find w3schools a really good place when I need to be reminded of half-forgotten syntax details, but a pretty poor place for learning new concepts. Yes - get yourself a good book!
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to assign one variable value to another xsl variable in xsl Anil_Base XSLT 3 March 24th, 2009 02:17 PM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
XSL Variable and/or Parameter Question ripple XSLT 9 September 1st, 2006 01:16 PM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 07:05 AM



All times are GMT -4. The time now is 01:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc