Project

Profile

Help

How to connect?
Download (2.71 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.6 / hec / samples / xqueryExamples.php @ aff640e6

1
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
    <head>
4
        <title>Saxon/C API design use cases</title>
5
    </head>
6
    <body>
7
        <?php 
8
            
9
            /* simple example to show transforming to string */
10
            function exampleSimple1($proc, $xmlfile, $queryFile){
11
                $proc->setSourceFile($xmlfile);
12
                $proc->setQueryFile($queryFile);
13
                  //$proc->setProperty('base', '/');      
14
                $result = $proc->queryToString();               
15
                if($result != null) {               
16
                echo '<b>exampleSimple1:</b><br/>';                
17
                echo 'Output:'.$result;
18
                } else {
19
                        echo "Result is null";
20
                }
21
                $proc->clearParameters();
22
                $proc->clearProperties();            
23
            }
24
            
25
            /* simple example to show transforming to file */
26
            function exampleSimple2($proc){
27
                $sourceNode = $proc->parseString("<foo xmlns='http://one.uri/'><bar><b>text node in example</b></bar></foo>");
28
                if($sourceNode !=null){
29
                        /*echo "Name of Class " , get_class($sourceNode) , "\n";                         
30
                        $str = $xdmvalue->getStringValue();
31
                        if($str!=null) {
32
                                echo "XdmValue:".$str;
33
                        } */
34
                        $proc->setSourceValue($sourceNode);
35
                } else {
36
                        echo "Xdmvalue is null";
37
                }
38
                $proc->setQueryContent("declare default element namespace 'http://one.uri/'; /foo");
39
                $result = $proc->queryToString();
40
                echo '<b>exampleSimple2:</b><br/>';                
41
                if($result != null) {               
42
                  echo 'Output:'.$result;
43
                } else {
44
                        echo "Result is null";
45
                }
46
                       $proc->clearParameters();
47
                $proc->clearProperties();
48
            }
49

    
50
            
51
            
52
            $books_xml = "query/books.xml";
53
            $books_to_html_xq = "query/books-to-html.xq";
54
            $baz_xml = "xml/baz.xml";
55
            $baz_xsl = "xsl/baz.xsl";
56
            $foo2_xsl = "xsl/foo2.xsl";
57
            $foo3_xsl = "xsl/foo3.xsl";
58
            $err_xsl = "xsl/err.xsl";            
59
            $err1_xsl = "xsl/err1.xsl";
60
            $text_xsl = "xsl/text.xsl";
61
            $cities_xml = "xml/cities.xml";
62
            $embedded_xml = "xml/embedded.xml";
63
            $multidoc_xsl = "xsl/multidoc.xsl";
64
            $identity_xsl = "xsl/identity.xsl"; 
65
            
66
            $proc = new SaxonProcessor();
67
                
68
                
69
            $version = $proc->version();
70
               echo '<b>PHP XQuery examples</b><br/>';
71
            echo 'Saxon Processor version: '.$version;
72
            echo '<br/>';        
73
            exampleSimple1($proc, $books_xml, $books_to_html_xq);
74
            echo '<br/>';
75
            exampleSimple2($proc);
76
            echo '<br/>';            
77
           
78
            unset($proc);
79
        
80
        
81
        ?>
82
    </body>
83
</html>
(3-3/5)