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 29th, 2010, 12:01 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

It depends on what you are trying to accomplish.

If you are trying to apply the the template to all the person elements where age > 18 and to all the person elements where age < $age then you would use | to create a union of the two groups. In the scenarios where $age is greater than 18 this would however mean it applies the template to all person elements.

<xsl:apply-templates select="$root/person_list/person[age &lt; $age] | $root/person_list/person[age &gt; 18]"/>

If you want to only apply the template to people who are between 18 and $age, then the filters should both appear within the predicate.

<xsl:apply-templates select="$root/person_list/person[age &lt; $age and age &gt; 18]"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 29th, 2010, 12:06 PM
Registered User
 
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<xsl:function name="my:name"> 
    <xsl:param name="name"/>
    <xsl:apply-templates select="contains($person[@name], $name])"/>
</xsl:function>
Thanks for the n-th time! I am really speechless now!
Just have another one: how do I filter by name then?
 
Old March 29th, 2010, 12:38 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

a) $person doesn't exist, unless you created it somewhere else and your just not telling us.
b) some of these questions appear to be fairly basic XSLT/XPath 101 type questions. Try having a look at a tutorial site like W3Schools: http://www.w3schools.com/xpath/xpath_syntax.as. You'll get more from learning the general rules, rather than asking us for specific examples.

If you still can't work it out then come back and let us know how you've progressed.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 29th, 2010, 12:58 PM
Registered User
 
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I forgot to mention. What I added myself is this declaration:
Code:
<xsl:variable name="person" select="/person_list/person"/>
Thanks for the page listed for reference, actually I am already familiar with all the information at w3schools on the subject (XML, XSL, XPath), and what I find hard to figure out is what I ask here.

I know that this example is suitable for the particular case:
Code:
title[@lang='eng']
but what I want is to check whether $person[@name] contains the parameter $name. Unfortunately, I get an error saying that I am giving an xs:boolean where a node() is expected.

Last edited by Nasko26; March 29th, 2010 at 01:11 PM..
 
Old March 29th, 2010, 01:50 PM
Registered User
 
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would you, please, help me here? I promise I won't be dwelling on the same subject anymore. I just need a proper solution for this, as I can't figure it out myself.

Thanks!
 
Old March 29th, 2010, 01:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you've got a new question, start a new thread. Don't keep asking supplementaries on the same thread. People lose track of what you've asked and what's been answered, and no-one wants to read through the whole thread to find out the context for the final question.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 29th, 2010, 04:31 PM
Registered User
 
Join Date: Mar 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<xsl:apply-templates select="$person[contains(@name, $name)]"/>
Alright, here is my working solution finally. Thank you very much for the generosity! No sarcasm here - only to myself because it took me so long to figure it out on my own!

I'd really like to skip Mr Michael Kay's post above mine, I wish him good luck and all the best!

Last edited by Nasko26; March 29th, 2010 at 04:34 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter XML file with an XSLT using DTD menhir666 XSLT 1 February 3rd, 2009 11:50 AM
Filter using ObjectDataSource and Custom Objects tna55 ASP.NET 2.0 Basics 5 July 17th, 2007 01:07 PM
add function to custom toolbar Vince_421 Access VBA 0 May 20th, 2006 10:36 AM
custom JavaScript Trim function crmpicco Javascript How-To 2 January 18th, 2006 12:53 PM
FUNCTION FILTER DATA FROM SQL DATABASE abofoma00 Javascript 1 November 21st, 2005 11:28 AM





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