XSLT - Extract leading integers from text string

Discussion in 'XML' started by grghoward@no.spam.email.com.no.spam, Mar 2, 2005.

  1. Guest

    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
     
    , Mar 2, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Tempore 22:29:52, die Wednesday 02 March 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > 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-view.cgi?userid=38041)
    Spread the wiki (http://www.wikipedia.org)
     
    Joris Gillis, Mar 2, 2005
    #2
    1. Advertising

  3. Guest

    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)
     
    , Mar 2, 2005
    #3
  4. Guest

    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
     
    , Mar 3, 2005
    #4
  5. Malte Guest

    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.
     
    Malte, Mar 3, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,663
    Cameron Laird
    Jun 9, 2006
  2. Replies:
    9
    Views:
    4,372
  3. John Nagle
    Replies:
    4
    Views:
    615
    James Antill
    Aug 7, 2007
  4. Delaney, Timothy (Tim)
    Replies:
    0
    Views:
    581
    Delaney, Timothy (Tim)
    Aug 7, 2007
  5. Mladen
    Replies:
    5
    Views:
    194
    Peter Scott
    Feb 22, 2011
Loading...

Share This Page