Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2011, 08:35 AM
Registered User
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in XSLT...

Hi All,

I have a requirment to impelment Cocke–Younger–Kasami (CYK) algorithm in the XSLT and transform the XML to produce new XML file. Could you please tell me if is it possible in the XSLT.

If yes, could you please give me an idea or example code.

I have seen the implementaion of the this algorithm in 'Java' but not able to fine the example code in XSLT.

I have tried my self but not able to achieve what I am after using XSLT.

Many thanks in advance. Your help much appriciated.

Regards
John
 
Old December 10th, 2011, 09:05 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Seeing as it is unlikely anyone even knows what the CYK algorithm is it is unlikely we will be able to help you with such a request unless you give us more to go on.

Generally you specify the input XML, what you would like the resulting output XML to look like and what attempts you have made to perform the transformation yourself.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old December 10th, 2011, 09:59 AM
Registered User
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sam,

Thank you for your quick reply.

To have a brief idea about CYK algorithm please have a look on the link below:

http://en.wikipedia.org/wiki/CYK_algorithm

There are two input xml like below I have to pass sentance.xml in the xslt and then based on the words in each sentance I have to read the values at runtime from the Rule.xml file and then produce the new XML given below.

1) sentance.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<sentances>
    <sentance>dog bark</sentance>
    <sentance>cat drink milk</sentance>
</sentances>
2) Rule.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<allrules>
    <rules>
        <rule cat="s">
            <rulechild cat="np"/>
            <rulechild cat="vp"/>
        </rule>
        <rule cat="vp">
            <rulechild cat="vt"/>
            <rulechild cat="np"/>
        </rule>
        <rule cat="vp">
            <rulechild cat="vi"/>
        </rule>	
    </rules>
    <words>
        <word cat="vi">bark</word>
        <word cat="vt">drink</word>
        <word cat="pn">dog</word>
        <word cat="pn">cat</word>
        <word cat="pn">milk</word>
    </words>
</allrules>

OutPut XML should be like below:

Code:
<trees>
    <tree>
        <sentace>dog bark</sentace>
        <node cat="s">
            <node cat="np">
                <word cat="pn">dog</word>
            </node>
            <node cat="vp">
                <word cat="vi">bark</word>
            </node>
        </node>
    </tree>
    <tree>
        <sentace>cat drink milk</sentace>
        <node cat="s">
            <node cat="np">
                <word cat="pn">cat</word>
            </node>
            <node cat="vp">
                <word cat="vt">drink</word>
                <node cat="np">
                    <word cat="pn">milk</word>
                </node>
            </node>
        </node>
    </tree>
</trees>
Could it be possible to implement the CYK algorithm and produce the above out using XSLT.

Any idea or example code will be very greateful.

Thanks again.
John
 
Old December 10th, 2011, 03:37 PM
Registered User
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Someone please shed some light on this. really appriciated.

Thanks
John
 
Old December 10th, 2011, 07:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Reverse engineering a functional, declarative program from a procedural program is hard. You can simulate the algorithm, but it may be very inefficient. Very often it's better to start with the problem statement (which in this case seems to be designing a parser for a class of grammars) and to choose or design an algorithm for solving that problem which is better suited to a functional approach.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt problem rajashekhara XSLT 4 February 24th, 2009 08:16 AM
xslt problem mickhughes XSLT 3 March 28th, 2008 05:09 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
XSLT problem pendyalap XSLT 4 March 24th, 2006 04:08 PM
problem with xslt superwebba BOOK: Professional Ajax ISBN: 978-0-471-77778-6 5 March 10th, 2006 01:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.