Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] xsl:analyze-string

From: "M. David Peterson" <m.david@---------->
To:
Date: 8/2/2004 10:35:00 AM
Hey David,



While not a complete answer to your problem I wonder if this might be of help to 
you...



http://blogs.msdn.com/the1/archive/2004/03/29/102123.aspx



This is a coding challenge called "Phraser" put up by Zhanyong Wan whom if you 
are not already familiar with comes from the Haskell school of thought (his 
dissertation for his Ph.D. in Computer Science from Yale was "Functional 
Reactive Programming for Real-Time Reactive Systems".



The Challenge:



In his words... "Your task is to write a program that finds all possible ways to 
phrase a phone number.  By "phrase" I mean using a mixture of numbers and 
English words to spell out the number.  For example, the number 642-394-6369 can 
be phrased as nice-window, nice-wind-ox, nice-win-fox, nice-9-in-fox, etc."



He created his recursive solution using Haskell and I wonder if his 
functional-programming-based algorithm (he writes a fantastic explanation 
regarding the thought process behind his solution) might help you solve the 
problem you are running into.



I've been meaning to attempt an XSLT solution to his challenge and if I can ever 
find the time I will most definitely make an attempt...  None-the-less, thats of 
know help to you now! :)  But maybe this is close enough to your issue that it 
may be of some use...



HTH's!



Best regards,



<M:D/>




David.Pawson@xxxxxxxxxxx wrote:
Problem:



I have xml looking like
   <record>19/08/1992  09:08            111938 500014.08b</record>

Of interest is the last field, the dos file name.
Its general form is
nnnnnn.nnA   n=int, A =A-Z.

I can use the analyze-string to parse this (mostly),
I'm missing a processing model to take care of exceptions.

E.g. xxx.01a is a particular (valid form).
On occasions someone has misnamed the file xxx.ola  using o instead
of 0 letter l instead of 1.

I'm missing the nest of cases: My code is shown below.
What's the logic to posively select all the known/valid combinations
are exhausted?
I want to add some form of error markup to identify these rogues.

Valid options include, for regex-group(5)



nnb
nnm
nnl
nnf
lab

TIA, regards DaveP







<xsl:template match="record">
  <xsl:analyze-string  select="." flags="i" regex=
"([0-9]+/[0-9]+/[0-9]+) +([0-9]+:[0-9]+) +([0-9]+) +([0-9]+)\.([0-9a-z]+)" >
    <xsl:matching-substring>
      <file>
        <nm><xsl:value-of select="regex-group(4)"/></nm>
        <ext><xsl:value-of select="regex-group(5)"/></ext>
        <xsl:analyze-string select="regex-group(5)" flags="i" regex=
"([0-9]{{1,2}})([a-z])">
          <xsl:matching-substring>
            <vol><xsl:value-of select="regex-group(1)"/></vol>
            <type>
              <xsl:choose>
                <xsl:when test="regex-group(2) = 'b' or regex-group(2) =
'B'">
                  <xsl:text>braille</xsl:text>
                </xsl:when>
                <xsl:when test="regex-group(2) = 'm' or regex-group(2) =
'M'">
                  <xsl:text>Moon</xsl:text>
                </xsl:when>
                <xsl:when test="regex-group(2) = 'l' or regex-group(2) =
'L'">
                  <xsl:text>ATOD</xsl:text>
                </xsl:when>
               <xsl:when test="regex-group(2) = 'f' or regex-group(2) =
'F'">
                  <xsl:text>DiskFile</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="."/>
                </xsl:otherwise>
              </xsl:choose>
            </type>
          </xsl:matching-substring>
        </xsl:analyze-string>

          <xsl:if test="regex-group(5)='lab'">
            <type>label</type>
          </xsl:if>
    </file>
    </xsl:matching-substring>
  </xsl:analyze-string>
</xsl:template>


Regards DaveP.



**** snip here *****


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent