Re: [xsl] Identifying patterns within texts

Subject: Re: [xsl] Identifying patterns within texts
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 29 Nov 2007 14:31:58 -0800
> if I have an element with text in it:
>
>
>
>                        <item>What is 1/2 in decimal format?</item>
>
>
>
>
>
> Is there a way using a style sheet to actually manipulate the text such
> that the resulting output would be:
>
>              < question>What is <math>1/2</math> in decimal
> format</item>
>



Yes,

Just give us the grammar that generates the sentence.

Then simply follow the steps necessary to work with the LR-Parsing
Framework of FXSL 2.0.

In the FXSL CVS there are examples such as parsing JSON. I have
implemented XPath 2.0 parsing as well.

Here is the signature of the f:lr-parse() function:

   23  <xsl:function name="f:lrParse" as="element()*">
   24    <xsl:param name="ppTables" as="element()"/>
   25    <xsl:param name="pInput" as="xs:string*"/>
   26    <xsl:param name="pFunLex" as="element()"/>
   27    <xsl:param name="pFunOnRuleReduced" as="element()"/>
   28 .......................................

   35  </xsl:function>



The meaning of the parameters is the following:

$ppTables   -- the YACCX - generated parsing tables (in XML format)
for this grammar. YACCX is a modified Berkeley YACC that produces such
parsing tables.
                         YACCX can be downloaded from the "tools"
subdirectory of the CVS

$pInput        -- the specific instance (of a sentence of the
language) to be parsed.

$pFunLex   -- the function (a template reference to it) that performs
the lexical analysis. It takes the string and the current position in
the string. The result is a
                       sequence of the next position in the string,
the token type just recognized (such as "NUMBER") and the exact value
that matched this token
                      (such as 223)

$pFunOnRuleReduced  -- the function (a template reference to it) that
is called every time a particular grammar rule is reduced. It takes
the rule
                                             (an xml element in the
document provided by $ppTables and the "value stack" ( a sequence of
"values" corresponding to the symbols
                                             comprising this rule),
and produces the value that should be associated with this particular
recognition of the rule.




See for a complete example f:json-document() at:

   http://fxsl.cvs.sourceforge.net/fxsl/fxsl-xslt2/f/func-json-document.xsl?revision=1.9&view=markup&sortby=date




-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Nov 28, 2007 1:24 PM, Themis, Jim <jthemis@xxxxxx> wrote:
> Well I am 4 days into understanding XSLT (and well 4 days into fully
> understanding xml).  I am working on a file conversion utility where it
> would be an xml to xml conversion.  In my research, I came across XSLT
> (along with XSL, XSL-FO,  XSD, DTD, etc).  My question is the following,
> if I have an element with text in it:
>
>
>
>                        <item>What is 1/2 in decimal format?</item>
>
>
>
>
>
> Is there a way using a style sheet to actually manipulate the text such
> that the resulting output would be:
>
>              < question>What is <math>1/2</math> in decimal
> format</item>
>
>
>
> Basically, I need to search through the text of an element and attempt
> to detect math?  Most of the tutorials use xml to HTML as an example and
> play with elements and attributes.  I was just wandering if the XSLT
> spec allows for this type of searching/parsing?
>
>
>
> Thanks,
>
> Jim Themis

Current Thread