473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT - Extract leading integers from text string

I am receiving a series of Microsoft Word documents from web clients
that they upload to my server. I need to convert them to XML to pass
through to another system. I have done this through Microsoft Word
2003 with the "Save as XML" option. Now the tricky part is that a
portion of these documents contains a numbered outline. Unfortunately,
I need to remove the numbering before passing the data to the next
system. Here is an example of what I am talking about:

1.{Tab}Check on the status of feedback from the newsgroup.
2.{Tab}If response received, read the response
3.{Tab}If the response applies, use it

(Replace the {Tab} with a tab key...). Unfortunately, there is no
guarantee that it will be a tab key. Some users have been uploading a
true outline formatted document. As such, I need to build in a "slop
factor" if possible.

After the document is saved as XML using the Microsoft Word 2003 "Save
as XML" option, the text string for the numbers looks like:

1.Check on the status...

See the lack of space between the numeral and the text? Now, I could
use the XSLT substring() function except that the number of items
sometimes is less than 10 (single digit), but has been seen to reach
over 100 (triple digit). Does anyone know of a creative way to strip
away the leading integer plus the period from the text string? Or,
does anyone know of a way to determine the location of the decimal if
the characters before it are integers?

Any help would be greatly appreciated.

Greg Howard

Jul 20 '05 #1
4 2096
Tempore 22:29:52, die Wednesday 02 March 2005 AD, hinc in foro {comp.text.xml} scripsit gr*******@no.sp am.email.com.no .spam <gr*******@emai l.com>:
Does anyone know of a creative way to strip
away the leading integer plus the period from the text string? Or,
does anyone know of a way to determine the location of the decimal if
the characters before it are integers?

Any help would be greatly appreciated.


Maybe I didn't read your mail very good, but wouldn't "substring-after( p , '.')" work?
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2
It would if I knew for a fact that the sentence in question was indeed
part of the outline. But if the user includes a sentence in between
two outline items, then I would process a sentence unnecessarily. For
example

1.{Tab}Check on the status of replies from the newsgroup.
Note to self: This is important to do.
2.{Tab}Read responses.

I would prefer to build in as much prevention as possible without
having to switch over to an XML parser interface (like DOM)

Jul 20 '05 #3
This may not be this best or final answer but I thought I would share
what I found to work for me so that I can move on to other issues:

<xsl:if test="string-length(substrin g-before(., '.'))&lt;=3">
<xsl:value-of select="substri ng-after(., '.')" />
</xsl:if>

At least this way I can be sure I am not stripping off the leading
portion of a sentence that has a dollar amount buried in it. If anyone
has any further thoughts or ideas, please share them.

Oh, and thanks Joris Gillis for your earlier input. I failed to say it
when I responded.

-Greg

Jul 20 '05 #4
gr*******@no.sp am.email.com.no .spam wrote:
It would if I knew for a fact that the sentence in question was indeed
part of the outline. But if the user includes a sentence in between
two outline items, then I would process a sentence unnecessarily. For
example

1.{Tab}Check on the status of replies from the newsgroup.
Note to self: This is important to do.
2.{Tab}Read responses.

I would prefer to build in as much prevention as possible without
having to switch over to an XML parser interface (like DOM)


Something along this line:

1. get substring before '.'
2. use number() on the result
3. test result of number() against NaN
4. if !NaN, get the substring after '.'

Clumpsy, but doable.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2035
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the following sample document: <root> <a b="1" />
6
2848
by: David Walker | last post by:
Hi, I have an XML file created by a third party in which an element with a simple content model has a text value consisting of 2 parts separated by a colon, like this <link>machine:port</link> Is XSLT capable of parsing the value of a <link> element, to separately extract the portions before and after the colon?
4
1820
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
5
11490
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
4
2154
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an XSLT to produce HTML code. The problem I have is that no matter what translation it runs through, it ALWAYS includes data that I don't match in...
8
6040
by: nick | last post by:
Hi all can any one please tell me what is wrong in this code?? I'm new to deal with text files and extract data. i'm trying to look for data in a text file (3~4 pages) some lines start with a word "red" first if find(red) then print the last 5 letters of that string and if red is not found at the begining of the string then do nothing and...
4
1917
by: shaun roe | last post by:
I should like to count the frequency of strings embedded in a longer string, space separated. Specifically, I have: <phiModule> 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 8 5 5 5 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 6 7 7 7 8 8 8 8 9 9 9
12
11562
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I don't want to have to use some external program or script to parse the csv first if possible
3
4513
by: joelkeepup | last post by:
Hi, im trying to create a text email message using xslt template , the transforms work great, but the newlines and whitespace in the xslt doc are removed. Is there a setting somewhere I have missed: My template is: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform"...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.