Loading ...
Sorry, an error occurred while loading the content.

[Clip] Re: regex/ iteration

Expand Messages
  • Claes Gauffin
    Hello Stephen, ... ext ... ext ... _text ... Well this is certainly doable in a clip. The following is rather ad hoc and could be
    Message 1 of 5 , Apr 26, 1999
    • 0 Attachment
      Hello Stephen,

      At 07:52 1999-04-26 -0400, you wrote:
      >
      >and <products>...</products> can be found in differeent tagging
      >contexts.
      >
      >eg:
      ><ihave>very_large_multiline_text_string<prodcuts>...nbr...</products>more_t
      ext</ihave>
      ><iwant>very_large_multiline_text_string<prodcuts>...nbr...</products>more_t
      ext</iwant>
      ><youwant>very_large_multiline_text_string<prodcuts>...nbr...</products>more
      _text</youwant>
      >
      >interested in the grand total, and the totals of nbr in
      ></ihave>,</iwant> etc. Your clip returns the grand total of all nbrs --
      >thanks -- I fear that the subtotalling requires search capabilities a
      >little beyond that the clip language has to offer, and I'll have to drag
      >an external XML parser into the clip. The various results will be
      >printed in the document from which the clip was run in some predefined
      >position.

      Well this is certainly doable in a clip. The following is rather ad hoc and
      could be elaborated with a panel for data entry, but I think it will do
      what you want.
      The fact is, I use NTB clips rather a lot in maintaining SGML systems.
      Writing small utilities to support data entry, parsing, navigation in large
      files, etc, is quite simple and veeeery time saving.

      Regards /Claes

      ;Define the contexts
      ^!SetArray %context%="Ihave";"Iwant";"Youwant";"Youget"
      ^!set %contextix%=0
      ^!Set %total%=0
      ^!SetArray %part%="0";"0";"0";"0"
      ^!set %partix%=0

      ;Find a context
      :nomorehits
      ^!If ^%contextix%=^%context0% done
      ^!Inc %contextix%
      ^!Inc %partix%
      ^!Find "<^%context^%contextix%%>" TIWS
      ^!Set %startrow%=^$GetRow$
      ^!Set %startcol%=^$GetCol$
      ^!Find "</^%context^%contextix%%>" TIS
      ^!Set %endrow%=^$GetRow$
      ^!Set %endcol%=^$GetCol$

      :nexttagpair
      ^!SetCursor ^%startrow%:^%startcol%
      ^!SelectTo ^%endrow%:^%endcol%
      ^!Find "<products>.*</products>" RHS
      ^!IfError nomorehits

      ^!Set %startrow%=^$GetRow$
      ^!Set %startcol%=^$GetCol$
      ^!Find "[0-9]" RHS
      ^!IfError nexttagpair
      ^!Set %nbr%=^$GetSelection$
      :nbrloop
      ^!Select +1
      ^!IfFalse ^$IsNumber("^$GetSelection$")$ gotnumber
      ^!Set %nbr%=^$GetSelection$
      ^!Goto nbrloop
      :gotnumber
      ^!Set %total%=^$[^%total%+^%nbr%;0]
      ;^!continue %part^%partix%%=^$[^%part^%partix%%+^%nbr%;0]
      ^!set %part^%partix%%=^$[^%part^%partix%%+^%nbr%;0]
      ^!Goto nexttagpair
      :done
      ^!Jump Text_end
      In ^%context1% = ^%part1
      In ^%context2% = ^%part2
      In ^%context3% = ^%part3
      In ^%context4% = ^%part4
      total is ^%total%


      ------------------------------------------------------------------------
      eGroup home: http://www.eGroups.com/group/ntb-clips
      Free Web-based e-mail groups by eGroups.com
    Your message has been successfully submitted and would be delivered to recipients shortly.