XSLT - Extract leading integers from text string

G

grghoward

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
 
J

Joris Gillis

Tempore 22:29:52 said:
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,
 
G

grghoward

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)
 
G

grghoward

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(substring-before(., '.'))&lt;=3">
<xsl:value-of select="substring-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
 
M

Malte

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top