Subject: [xsl] Re: xsl-list Digest 7 Apr 2005 05:10:00 -0000 Issue 380 From: Shivani Goel <goelshivani@xxxxxxxxx> Date: Thu, 12 May 2005 12:04:09 -0700 (PDT) |
Thanks Michael, David. You were both prompt and accurate... I appreciate it greatly! Michael said: Try adding quotes, e.g. 'abcdefghijklmnopqrstuvwxyz' which worked perfectly. However there is little quirk (annoying one, at that) that I wanted to report, and perhaps someone could explain it: It seems the following do not function exactly identically: <xsl:if test="@name[not (translate (., '$lowerCase', '$upperCase') = translate following::Program/@name, '$lowerCase', '$upperCase'))]"> $lowerCase & $upperCase are defined as follows: <xsl:variable name="upperCase" select="ABCDEFGHIJKLMNOPQRSTUVWXYZ"/> <xsl:variable name="lowerCase" select="abcdefghijklmnopqrstuvwxyz"/> ____ versus ____ <xsl:if test="@name[not (translate (., 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = translate (following::Program/@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))]"--> The second <xsl: if> works fine (in that 'project oregon' and 'Project Oregon' nodes in my XML source/dataset are recognised as identical, ie the translate () is performed perfectly/as intended). *Not So* with the first <xsl: if> where I use variables instead of the string 'A...Z' Not that both refer to nodes /axes in the exact same manner. Any ideas why? Many thanks, Shivani. ------------------------------ Date: Wed, 6 Apr 2005 14:07:51 -0700 (PDT) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx From: Shivani Goel <goelshivani@xxxxxxxxx> Subject: On-the-fly case-conversion w. translate() Message-ID: <20050406210751.9888.qmail@xxxxxxxxxxxxxxxxxxxxxxx> I've been through this list (and also googled my query), but am wits end as why my code doesnt work: This is a fragment from my XML file: <Program name="project oregon"> ... .. </Program> <Program name="project oregon"> .. ... ....... </Program> <Program name="Project Oregon"> ....... ........ ....... </Program> <Program name="Spring Beach Cleanup"> .............. ......... </Program> <Program name="Spring Beach Cleanup"> ... </Program> I want to display the value of attr 'name', in an HTML <select> element (aka drop down list), while eliminating duplicates, for which, I do this: <select class="formDropDown1" name="program" id="program"> <xsl:if test= "@name [not (self::node() = following::Program/@name)]"> <option> <xsl:attribute name="value"><xsl:value-of select="@name"/></xsl:attribute> <xsl:value-of select="@name" /> </option> </xsl:if> The above works flawlesslessly to eliminate duplicates (though from what I've read, using 'following' axis may lead to pefomance issues with very large XML files...). However, *and this is my reason for posting to the list*, I want to have "project oregon" and "Project Oregon" display only once! I tried the following to translate the respective nodes to identical (upper) case, as follows: <xsl:if test="@name[not(translate (self::node(), abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ) = translate (following::Program/@name, abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ))]" > This does NOT work! Duplicates are eliminated, however, "project oregon" & "Project Oregon " are treated as separate /unique strings. What am I doing wrong? Any suggestions will be gratefully welcome. Shivani. __________________________________ Do you Yahoo!? Yahoo! Personals - Better first dates. More second dates. http://personals.yahoo.com ------------------------------ Date: Wed, 6 Apr 2005 22:19:49 +0100 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx From: David Carlisle <davidc@xxxxxxxxx> Subject: Re: [xsl] On-the-fly case-conversion w. translate() Message-Id: <200504062119.WAA22311@xxxxxxxxxxxxxxxxx> <xsl:if test= "@name [not (self::node() = following::Program/@name)]"> self::node() can be written more simply as . translate (following::Program/@name, abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ))]" This has come up already today (and is a faq) lthough I'm not sure what you'd search for. If you use a node set as an argument to a string function xslt1 takes the first node in document order in the set and uses that nodes string value, it ignores any other nodes. it (might be) a bit more efficient or at least clearer to use following-sibling on the element node rather than following from the attribute node, test="@name=following-sibling::Program/@name" tests if this nodes name attribute is equal to any of the following nodes names. test="translate(@name,$u,$l)=translate(following-sibling::Program/@name,$u.$l)" tests if this nodes name attribute is equal to the _immediately following_ Program nodes name attribute. In this case you can do test="following-sibling::Program/@name[translate(.,$u.$l) =translate(current()/@name,$u,$l)]" David ________________________________________________________________________ ------------------------------ Date: Wed, 6 Apr 2005 23:08:57 +0100 To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> From: "Michael Kay" <mike@xxxxxxxxxxxx> Subject: RE: [xsl] On-the-fly case-conversion w. translate() > <xsl:if test="@name[not(translate (self::node(), > abcdefghijklmnopqrstuvwxyz, > ABCDEFGHIJKLMNOPQRSTUVWXYZ) = translate > (following::Program/@name, abcdefghijklmnopqrstuvwxyz, > ABCDEFGHIJKLMNOPQRSTUVWXYZ))]" > > > This does NOT work! Duplicates are eliminated, > however, "project oregon" & "Project Oregon " are > treated as separate /unique strings. What am I doing > wrong? > Try adding quotes, e.g. 'abcdefghijklmnopqrstuvwxyz' Michael Kay http://www.saxonica.com/ Discover Yahoo! Stay in touch with email, IM, photo sharing and more. Check it out! http://discover.yahoo.com/stayintouch.html
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] xsl variable not resolved, Ross, Douglas | Thread | RE: [xsl] Re: xsl-list Digest 7 Apr, Michael Kay |
Re: [xsl] Grouping with XSL, Thea Burger | Date | RE: [xsl] Re: xsl-list Digest 7 Apr, Michael Kay |
Month |