Re: [xsl] Parsing a string

Subject: Re: [xsl] Parsing a string
From: Jeff Kenton <jeffrey.kenton@xxxxxxxxxxx>
Date: Thu, 03 Jun 2004 15:55:30 -0400

As you have found, XSLT isn't necessarily the best tool for this job. XSLT 2.0 is somewhat better, because it has regular expression support.


But, the real question is, what is your application? Would Perl, or lex (with or without yacc), or just C be a better tool for you here?

xptm@xxxxxxx wrote:
Hi guys:

I have a string like

$select = SELECT * FROM aTable WHERE aColumn='something' ORDER BY anotherColumn

and want to parse this to variables such

fields = "*"
from = "aTable"
where = "aColumn='something' "
order = "anotherColumn"

so i made this:

    <xsl:attribute name="fields">
        <xsl:value-of
select="substring-before(substring-after($select,'SELECT'),'FROM')"/>
    </xsl:attribute>
    <xsl:attribute name="from">
        <xsl:value-of
select="substring-before(substring-after($select,'FROM'),'WHERE')"/>
    </xsl:attribute>
    <xsl:attribute name="where">
        <xsl:value-of
select="substring-before(substring-after($select,'WHERE'),'ORDER BY')"/>
    </xsl:attribute>
     <xsl:attribute name="order">
        <xsl:value-of select="substring-after($select,'ORDER BY')"/>
    </xsl:attribute>

This works, off-course, when $select is writen in that way, but if it is, for
instance

SELECT * FROM aTable ORDER BY anotherColumn
SELECT * FROM aTable ORDER BY anotherColumn WHERE aColumn='something'

and worst

SELECT * FROM aTable WHERE aColumn=(SELECT aColumn FROM anotherTable WHERE
anotherColumn='somethingelse')

then it won't work. Of course i can put a lot of  xsl:if and xsl:when, but
hopefuly there's another way to do it.

Someone has any ideia?







O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--



--


-------------------------------------------------------------------------
=    Jeff Kenton      Consulting and software development               =
=                     http://home.comcast.net/~jeffrey.kenton           =
-------------------------------------------------------------------------




Current Thread
  • Parsing a string
    • xptm - Thu, 3 Jun 2004 20:34:33 +0100
      • Jeff Kenton - Thu, 03 Jun 2004 15:55:30 -0400 <=
        • Mayo - Thu, 3 Jun 2004 13:38:20 -0700
        • xptm - Thu, 03 Jun 2004 22:08:43 +0100
      • Michael Kay - Thu, 3 Jun 2004 22:52:18 +0100