[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: newbie - parameters with/without values??

Subject: RE: newbie - parameters with/without values??
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 05 Oct 2004 09:37:30 +0000
xsl for each parameters
Hi Hardy,

I will try explaining.

The [something] is a filter.
A <xsl:for-each select="person"> would select all person elements (that are children of the current element).
When you filter it with "person[gender = $gender]" you say that the processor must only select those person elements that have a child element with the value in the variable $gender.
Here you have a syntax error as you have written [gender = '$gender'] which says that the element
gender (which is a child of person) must have a string value of "$gender".
That would be the same in many other programming languages as the difference between
(shown in JavaScript syntax)
var a = "This";
var b = a; ~ gender = $gender
var b = "a"; ~ gender = "$gender"


If the filter is true for all elements, then it is the same as having no filter:
<xsl:for-each select="person[1=1]"> is the same as <xsl:for-each select="person">
and if the filter is an absurdity (false for all elements), ie. <xsl:for-each select="person[1=0]"> then no elements are chosen.


So in your expression (syntax error corrected):
<xsl:for-each select="person[$gender='' or gender=$gender]>
If $gender is the default, then the first expression will always be true, and every person (element) is then chosen.
If, as you said, $gender is 'Male' then the first expression is false, and the second expression will only be true in the example that you mentioned (the Joe person).


I hope that this helps.

Regards,
Ragulf Pickaxe :-)



From: "Hardy Merrill" <HMerrill@xxxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>,<mike@xxxxxxxxxxxx>
Subject: RE:  newbie - parameters with/without values??
Date: Mon, 04 Oct 2004 13:01:00 -0400

I'm trying to understand...

Given the XML document below with 2 "person" nodes in it, if my XSL
document looks like this:
---------------------------------------------
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" />

<xsl:param name="gender"/>
<xsl:param name="city"/>

<xsl:template match="/my_document">
    <xsl:for-each select="person[$gender = '' or gender = '$gender']">
        <p>Name: <xsl:value-of select="name"/></p>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------
1. if the value of parameter "gender" is the "default default" (""),
then what if anything will be displayed?

2. if parameter "gender" has a value of "Male", will "Name: Joe" be the
output?

I read in your (Michael's) book about the "or" only evaluating the 2nd
operand if the 1st operand is false.  But I still don't quite understand
how the xpath select will be evaluated if the parameter has a "" value -
the first operand ($gender='') will then be true, which will essentially
make the xpath select="person[$gender='']" right?  And I don't know how
xpath will interpret that.

Please straighten me out ;-)

TIA.

Hardy Merrill

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.