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 October 27th, 2010, 11:41 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Matching Whitespace

I'm trying to match any element node, whose child text node contains a carriage return or line feed. I have something that's working, but it seems inelegant to me. Maybe I'm just being picky, but is there any improvement I could make to this? I'm using saxon 8.9 (2.0 transformation). I've looked into using "matches()" but I cannot get a regular expression to work properly. Mostly, because I'm not very good at regex :)

Suggestions? Improvements?

Code:
<xsl:template match="*[text()[contains(.,'&#xA;')] | text()[contains(.,'&#xD;')]]">
 
Old October 27th, 2010, 11:49 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I would probably write
Code:
<xsl:template match="*[text()[contains(., '&#xA;') or contains(., '&#xD;')]]">
but I don't think that is more elegant than yours.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
iceandrews (October 27th, 2010)
 
Old October 27th, 2010, 12:34 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A text node is very unlikely to contain a CR, because unless it's written as a numeric character reference, the XML parser will turn it into a NL.

And testing whether the string-value of the element contains a newline is equivalent to testing whether it has a text node that contains a newline. So I think it's just

Code:
<xsl:template match="*[contains(., '&#xa;')]">
Saxon 8.9 is getting very old, by the way: time you upgraded.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
iceandrews (October 27th, 2010)
 
Old October 27th, 2010, 12:49 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

I ran into some problems with just doing "contains()" directly on the element node. Unless the document was using "<xsl:strip-space elements="*" />" it was matching on pretty much the entire document.

Quote:
Originally Posted by mhkay View Post
Saxon 8.9 is getting very old, by the way: time you upgraded.
You're telling me! We run into bugs every once and a while linked back to 8.9. Unfortunately, we're tied to and Enterprise Service Bus product (Sonic) that has the version of Saxon built in statically. We've tried to just upgrade the saxon processor portion of the ESB product, but that blows up. We also have upgraded sonic a couple times, but that still haven't adopted 9+ version of saxon.

To be honest, I'm just happy to be able to use XSLT 2.0 compared to 1.0. I'll deal with the older version for now.

Thanks for your suggestions, much appreciated.

Last edited by iceandrews; October 27th, 2010 at 12:53 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
In IE6 How do you get Whitespace??? David P. Manning CSS Cascading Style Sheets 0 April 24th, 2007 08:01 AM
Displaying leading whitespace djmarquette XSLT 2 January 26th, 2005 10:39 AM
whitespace in label Twinklestar ASP.NET 1.0 and 1.1 Basics 4 July 28th, 2004 07:37 AM





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