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 February 29th, 2008, 12:20 AM
Registered User
 
Join Date: Feb 2008
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
 
Old February 29th, 2008, 03:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 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 -/
 
Old February 29th, 2008, 05:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





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 08: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 06:03 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM





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