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 6th, 2005, 11:56 PM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding a string in the text

I have a xml file that has the word "see" or "see also"(indefinite to any children of the root) which has to be looked. But only it should be considered if the following word to it is a tag, <hi>.
For example:
<p>...We believe in the power of the mind;; see <hi rend="smallcaps"> inspiration</hi>...</p>
or
<p>This situation may be a reflection of a debate... (see also <hi rend="smallcaps">debate</hi>)...</p>
I need to do this because I will manipulate the content of the <hi> element.
Any idea on how to do this? Thanks.

 
Old November 7th, 2005, 09:46 PM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have already found the solution:
tokenize(normalize-space(preceding-sibling::text()), ' ')[last()]='see'
or
tokenize(normalize-space(preceding-sibling::text()), ' ')[last()]='also'
and
tokenize(normalize-space(preceding-sibling::text()), ' ')[last()-1]='see'

 
Old November 8th, 2005, 05:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

preceding-sibling::text()[1] would be safer. In XSLT 2.0 you'll get an error if there's more than one.

I would do it with matches() and a regex myself, but your solution is OK.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 8th, 2005, 11:22 PM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're definitely correct with doing the task with match and regex because I encountered a problem with the case when the word "see" is preceded by a character like "(see" or ";see" and the uppercase and lower case of the words. Can you give some code examples on how to do the match and regex. Thanks.

 
Old November 9th, 2005, 05:12 AM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't bother anymore, I already found my solution:
<xsl:variable name="tex" as="xs:string*" select="preceding-sibling::text()"/>
<xsl:choose>
<xsl:when test="(tokenize(normalize-space(lower-case($tex[last()])), '\s[^s]?')[last()]='see' and not(ancestor::dummyarticle)) or (tokenize(normalize-space($tex[last()]), ' ')[last()]='also' and tokenize(normalize-space(lower-case($tex[last()])), '\s[^s]?')[last()-1]='see' and not(ancestor::dummyarticle))">
...
</xsl:when>
</xsl:choose>
Thanks anyway..


 
Old November 15th, 2005, 11:20 PM
Authorized User
 
Join Date: Oct 2005
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think there is a flaw with my work,
<xsl:variable name="tex" as="xs:string*" select="preceding-sibling::text()[1]"/>
<xsl:choose>
<xsl:when test="(tokenize(normalize-space(lower-case($tex[last()])), '\s[^s]?')[last()]='see' and not(ancestor::dummyarticle)) or (tokenize(normalize-space($tex[last()]), ' ')[last()]='also' and tokenize(normalize-space(lower-case($tex[last()])), '\s[^s]?')[last()-1]='see' and not(ancestor::dummyarticle))">
...
</xsl:when>
</xsl:choose>

when the text is " (see", it does not go to the when block, how come? Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding specific string martinrhague Access 7 November 2nd, 2006 12:54 PM
finding max string length if more than 2 elements srini XSLT 4 April 4th, 2006 01:08 PM
finding the string before a special character srini XSLT 2 December 16th, 2003 07:57 AM
Finding a specific character within a string tp194 Classic ASP Databases 2 October 12th, 2003 10:41 PM
Finding width of text jerimorris Javascript How-To 4 September 8th, 2003 02:34 PM





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