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 November 29th, 2012, 12:57 PM
Registered User
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Quick question

Relatively new to Xpath and XSLT - reading another developers code and don't quite understand what is happening.

To give context, XML file looks basically like this:

<root>
<BrowserBarTitle></BrowserBarTitle>
<Title>Random Title</Title>
</root>

I don't understand the second part of the union |

<xsl:value-of select="/*/BrowserBarTitle[string(.)] | /*/Title[not(string(/*/BrowserBarTitle))]" disable-output-escaping="yes"/>

Thanks,
Shannon
 
Old November 29th, 2012, 02:34 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 1.0 an xsl: value-of creates a text node with the string value of the first node of the selected node set. I think the posted snippet is an attempt to output either BrowserBarTitle or Title, depending on whether one of them is empty.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 29th, 2012, 02:44 PM
Registered User
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Martin, thanks for the response.

I am still not clear on this part:

/*/Title[not(string(/*/BrowserBarTitle))

From the output, I can see it selects the value of Title but don't understand how not(string(/*/BrowserBarTitle) fits into the picture.
 
Old November 30th, 2012, 05:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Read it as

Code:
if (string(/*/BrowserBarTitle))
then ""
else /*/Title
and it might be clearer. Note that there is no need for the value of the predicate in a filter expression to depend on the node being filtered.

In XSLT 2.0 you could write this as an "if" expression, but in XSLT 1.0 the filter expression is your only option (and you might prefer it anyway, since it's shorter).
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Just a quick question dietelmersglue BOOK: Beginning iOS Game Development 1 May 15th, 2012 10:49 AM
One quick question helovamut BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 1 March 16th, 2009 10:16 AM
Quick Question! arcadium Java GUI 1 August 5th, 2008 02:16 AM
Quick Question Ben Horne Forum and Wrox.com Feedback 1 March 22nd, 2004 03:29 PM
Quick If Then Question hcweb Classic ASP Basics 2 March 13th, 2004 02:13 PM





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