Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer 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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2008, 11:20 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default giving two conditions in match in xsl:key

Hi

I am new to XSLT.

here is my XML
<books>
  <book id = "1" pub-id = "" isenglish = "Yes" author = "abc1">History1</book>
   <book id = "2" pub-id = "" isenglish = "Yes" author = "abc2">History2</book>
   <book id = "3" pub-id = "" isenglish = "Yes" author = "abc3">History3</book>
   <book id = "4" pub-id = "" isenglish = "No" author = "abc">History4</book>
   <book id = "5" pub-id = "" isenglish = "Yes" author = "abc1">History5</book>
   <book id = "6" pub-id = "" isenglish = "No" author = "abc2">History6</book>
   <book id = "7" pub-id = "1" isenglish = "Yes" author = "abc4">History7</book>
   <book id = "8" pub-id = "" isenglish = "Yes" author = "abc5">History8</book>
</books>

using following key i can choose all booknodes where isenglish attribute value is Yes.
  <xsl:key name="bookByLanguage" match="book[@isenglish="Yes"]" use="id"/>

But i need to choose all book nodes where isenglish attribute value is Yes and pub-id is equal to blank.

Can anyone please help me to write this match where two conditions are checked at once.

Thanks in advance..
Vidhi
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old February 29th, 2008, 02:56 AM
samjudson's Avatar
Friend of Wrox
Points: 7,966, Level: 38
Points: 7,966, Level: 38 Points: 7,966, Level: 38 Points: 7,966, Level: 38
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,994
Thanks: 1
Thanked 164 Times in 163 Posts
Default

Single quotes inside your attributes. Use 'and' to have two conditions.

<xsl:key name="booksEnglishNoPub" match="book[@isenglish='Yes' and @pub-id='']" use="id"/>

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old February 29th, 2008, 04:40 AM
mhkay's Avatar
Wrox Author
Points: 15,993, Level: 54
Points: 15,993, Level: 54 Points: 15,993, Level: 54 Points: 15,993, Level: 54
Activity: 56%
Activity: 56% Activity: 56% Activity: 56%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,532
Thanks: 0
Thanked 197 Times in 194 Posts
Default

<xsl:key name="bookByLanguage" match="book[@isenglish="Yes"]" use="id"/>

I suspect you don't want to do that. xsl:key declares an index; the key() function uses the index to do a search. This particular declaration allows you to find an English book quickly if you know its id. But the id appears to be unique across all books, so if you know its id, you can find it without knowing whether or not it is English: using match="book" would give the same result.

I think I need to understand your requirements better.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference 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 deal with complex conditions in XSL file? Mateo1041 XSLT 10 October 9th, 2008 11:34 AM
Using key() and <xsl:key> freddy XSLT 2 January 18th, 2007 07:55 PM
How to Only Match Elements that Equal an XSL Var? tclancy XSLT 1 April 21st, 2006 04:05 PM
xsl:template match 'overlapping' ? Kabe XSLT 1 February 25th, 2005 05:03 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM



All times are GMT -4. The time now is 08:07 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
© 2011 John Wiley & Sons, Inc.