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 August 18th, 2005, 03:52 AM
Registered User
 
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search the contents of a node

Does anyone have a code example to search the contents of a node for a piece of search text, and return a number of instances please? XSLT1.0

I currently use the contains() function to determine whether the search text exists or not, but this is too simplistic and only gives a yes/no rather than the count that I require.

I was thinking I might have to have a recursive function and use substring-before/after but I don't want to over-engineer if there's a more obvious way that I'm just not seeing.

Thanks very much for any help

Andrew

 
Old August 18th, 2005, 04:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In 2.0 you can use xsl:analyze-string:

<xsl:variable name="hits" as="text()*">
  <xsl:analyze-string select="..the text.." regex="..the pattern..">
    <xsl:matching-substring>1</xsl:matching-substring>
    <xsl:non-matching-substring/>
  </xsl:analyze-string>
</xsl:variable>
There were <xsl:value-of select="count($hits)"/> hits

In 1.0 your approach of recursion using substring-before/after is the only way to do it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
search value of XML element/node in general deean XML 1 June 14th, 2008 03:17 AM
Search A Hierarchy Tree for Node where id=value sdaspen XSLT 4 February 2nd, 2007 06:34 PM
Copy all contents except current node in XSLT 2BOrNot2B XSLT 2 December 19th, 2006 06:44 PM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
VBA Script to search fields and display contents Jwill1014 Access VBA 8 June 2nd, 2005 07:33 AM





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