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 14th, 2012, 07:27 AM
Authorized User
 
Join Date: Mar 2012
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
Default XPath 2.0 regexp matching all strings except the words in a set

Dear all,

I'm trying to write a regexp which allows me to find all words that are not in a set of words e.g.

if the inputs are "one" "two" "three" "four" "five" "bla" "blabla" I only want to obtain all of them except "two" and "three".

Obviously something like
Code:
[^two]|[^three]
does not work. I would need the 'and' operator, but it does not exist, right?

PS: I'm using the function "matches" to check the content of an attribute, like in:
Code:
[matches(@name,[^two]|[^three])]
Thanks in advance for your help!
EastvanAxon
 
Old November 14th, 2012, 07:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't think regex is the right way to do this. If $stopwords is the set of words you want to exclude, and $input is the list of input words, then $input[not(. = $stopwords)] gives you the answer.
__________________
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:
EastvanAxon (November 14th, 2012)
 
Old November 14th, 2012, 08:06 AM
Authorized User
 
Join Date: Mar 2012
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Thanks for your answer.

I'm using regex because this is only a particular use case. Usually I set the value to just one name (because I want to get only strings matching that name).

here a piece of code which should be more explanatory:

Code:
<xsl:for-each select="[...]/function[matches(@name, document($config-file)/[...]/funcname)]">
	<xsl:variable name="currNode" select="position()"/>
	<xsl:variable name="uri" select= "[...]"/>
			
	<xsl:result-document href="{$uri}">
		<xsl:apply-templates select="/*">
			<xsl:with-param name="counter" select="$currNode"/>
		</xsl:apply-templates>
	</xsl:result-document>
</xsl:for-each>
where $configfile is a variable pointing to a file containing the regex. I believe I cannot use the solution you proposed because the file pointed by $configfile is meant to change, i.e. one can change the regex in order to change the result of the script, while the script must be general to address all cases and remain the same (selecting a particular function or all functions except some as in the example above).

I really hope this is possible. Otherwise I would like to know if there is another way to use the $configfile in order to be able to do the trick

Thanks again
EastvanAxon
 
Old November 14th, 2012, 08:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't believe this can be done using XPath 2.0 regular expressions.

A more flexible solution would be for your external file to contain the rules in terms of XPath expressions (you would need to use an extension such as saxon:evaluate() to evaluate them).
__________________
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:
EastvanAxon (November 14th, 2012)
 
Old November 14th, 2012, 09:00 AM
Authorized User
 
Join Date: Mar 2012
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Thanks a lot. I'll try to think about the viability of employing external XPath expressions.

Best,
EastvanAxon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching Numeric Strings with RegEx hugh@kmcnetwork.com VB How-To 3 October 7th, 2008 12:13 PM
RegExp matching substring mayasht Java Basics 4 May 11th, 2007 08:11 AM
Matching two strings jamie_t VB How-To 0 October 12th, 2005 03:40 AM
RegExp looping for multiple strings in string interrupt Javascript How-To 2 June 20th, 2005 05:37 AM
Bold Words in Strings SerranoG Access VBA 6 September 24th, 2004 06:46 AM





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