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 January 5th, 2011, 07:44 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default Complex template matches?

I've been trying to find a way to match parent elements that match one or more conditions while only returning unique results. As an example (listed below), how would I write a template match to match all the bookstore elements that contain either 'Harry Potter' or 'Learning XML' and are written in English?

Code:
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>
<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>
</bookstore>
The best I have been able to do is match the titles via the following:

Code:
 
<xsl:template match="//bookstore/book/title[@lang='eng'][text() = 'Harry Potter'] | //bookstore/book/title[@lang='eng'][text() = 'Learning XML']">
While I can traverse this to get to the bookstore, I'll get multiple hits resulting in the same bookstore. What I want to do is match the bookstore. However, it seems beyond me.
 
Old January 6th, 2011, 04:35 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Your match is returning matching titles, not matching bookstores, hence the duplication in your results.

You want something like this:

Code:
<xsl:template match="bookstore[book/title[@lang='eng' and text()='Harry Potter'] or book/title[@lang='eng' and text()='Learning XML']]">
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
whelanj (January 6th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete node that matches combobox? QuadFather XML 2 April 8th, 2010 08:40 AM
Matches help JohnBampton XSLT 4 August 11th, 2009 10:03 AM
Unable to get multiple matches iinf BOOK: Beginning Regular Expressions 1 October 9th, 2008 02:18 PM
Displaying 1 to 9 of 9 matches kumiko Classic ASP Basics 2 February 21st, 2008 05:12 PM
matches without repeated items pongup BOOK: Beginning Regular Expressions 0 April 7th, 2007 09:05 PM





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