[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:analyze-string

Subject: Re: xsl:analyze-string
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Mon, 02 Aug 2004 02:04:22 -0600
xsl analyze string
Oops, forgot the link to his solution (the original challenge post probably won't help you much!)

http://blogs.msdn.com/the1/archive/0001/01/01/106691.aspx

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 *****

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.