473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

XSL : Display First 4 words of a node in XSLT 1.0

Hi,


Following is the xml file:
-------------------------------------

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <wc>
  4.         Delhi is the capital of India
  5. </wc>
This xml contains 6 words and 5 blank spaces.

I am able to count the number of Words using XSLT 1.0.


********** Requirement is if count of blank spaces is 3 then first 4 words of the node is to displayed. *************




Following is the xsl:
--------------------------------

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.     <xsl:template match="/">
  3.         <xsl:call-template name="Word_Count">
  4.             <xsl:with-param name="text">
  5.                 <xsl:value-of select="wc"/>
  6.             </xsl:with-param>
  7.             <xsl:with-param name="space" select="' '"/>
  8.             <xsl:with-param name="count" select="0"/>
  9.         </xsl:call-template>
  10.     </xsl:template>
  11.     <xsl:template name="Word_Count">
  12.         <xsl:param name="text"/>
  13.         <xsl:param name="space"/>
  14.         <xsl:param name="count"/>
  15.         <xsl:choose>
  16.             <xsl:when test="contains($text, $space)">
  17.                 <xsl:call-template name="Word_Count">
  18.                     <xsl:with-param name="text">
  19.                         <xsl:value-of select="substring-after($text, $space)"/>
  20.                     </xsl:with-param>
  21.                     <xsl:with-param name="space" select="' '"/>
  22.                     <xsl:with-param name="count">
  23.                         <xsl:value-of select="number($count + 1)"/>
  24.                     </xsl:with-param>
  25.                 </xsl:call-template>
  26.             </xsl:when>
  27.             <xsl:otherwise/>
  28.         </xsl:choose>
  29.         No of Blank Spaces :    <xsl:value-of select="number($count)"/>
  30.         <br/>
  31.         No of Words            :    <xsl:value-of select="number($count) + 1"/>
  32.         <br/>
  33.         <xsl:text>.....................................</xsl:text>
  34.         <br/>
  35.     </xsl:template>
  36. </xsl:stylesheet>

Any help will be highly appreciated.....


Thnx,
Saurabh
May 17 '07 #1
1 2496
dorinbogdan
839 Expert 512MB
********** Requirement is if count of blank spaces is 3 then first 4 words of the node is to displayed. *************
Welcome to TheScripts TSDN....

If count of blanks = 3 then count of words = 4

So, you need the whole original text. No splitting is necessary.
May 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rolf Kemper | last post by:
Hi All, ned help on the example below. It works fine for msxml3/4 but has problems with saxon. Saxon complains "can not find matching function ..... " My target is to write style sheets...
1
by: Alex | last post by:
Hello, I don't have sufficient experience with XSLT, and would really appreciate somebody's help in me giving ideas on solving a problem I have. Let's consider the following XML file: ...
1
by: Omega375 | last post by:
Hello. I'll first start off by showing the structure of my xml-file. <root> <node path="X"> More nodes containing data </node> </root>
5
by: John Sever | last post by:
My transform in cludes a variable that holds a node set from the node-set() extension function. It the transformation works fine when using MSXML2 or msxsl.exe but not in VB.Net. My code looks...
18
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml...
4
by: elsigh | last post by:
I'm wondering if anyone has any ideas about a way to quickly convert an HTML DOM Node into an XML Document. The goal is that I want to perform XSLT on the Node, which is coded correctly as XHTML....
11
by: Webbert | last post by:
I am trying to display XML in a WebBrowser Control. I receive a data feed of XML and am trying to inject it into the control. I have not been successful in doing so. The only solution I have...
2
by: ofuuzo1 | last post by:
Hei, I have the following xml file and I have tried to write xslt to extract only the values of the first "record" node. It does not work. I need some help. I used ---- to represent indent. ...
6
by: Olagato | last post by:
I need to transform this: <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <url> <loc>http://localhost/index.php/index./Paths-for-the-extreme-player</ loc> </url> <url>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.