view software/eXist/webapp/mpdl/_stuff/testDev/dummy.xql @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children
line wrap: on
line source

xquery version "1.0";

declare namespace dummy = "http://archimedes.mpiwg-berlin.mpg.de"; 
declare namespace xlink = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; 

declare option exist:serialize "method=xml media-type=text/xml omit-xml-declaration=no indent=yes";

declare function dummy:getDummyDocument() as node() {
  let $bla := 
    document {
      element product {
        attribute dept { "ACC" },
        element number { 563 },
        element name { attribute language {"en"}, "Floppy Sun Hat"}
      },
      element product {
        attribute dept { "BCC" },
        element number { 564 },
        element name { attribute language {"en"}, "Floppy SBun Iat"}
      }
    }
  return $bla
};

declare function dummy:milestone-chunk($ms1 as node(), $ms2 as node(), $node as node()) as node()* {
(:
    Version 1.0 -- 7 Feb 2005 -- David Sewell
    Usage: The first two parameters are the starting and ending milestone elements in a
    document or document fragment. Example: $doc//pb[@n='1'], $doc//pb[@n='2'].
    The third parameter should initially be an element that is a parent or
    ancestor of all the milestones, like $doc//body or $doc//text. (This
    parameter is the only one that varies as the function is called
    recursively.)

    The function returns only a single node containing the content between the
    two milestones. To return, for example, all the pages in a book, call the
    function repeatedly by reiterating over every <pb>, where $ms2 will be
    either the following <pb> or, for the last one, the final node() in the
    document or document fragment.

    English-language explanation of the function operation:

    Test for node type. For an element, if it is (1) an ancestor or self of one
    of the two milestones, use the "element" function to return an element of
    the same name, with its content created by recursing over any child nodes. If
    it is (2) an element in between the two milestones, return the element. If
    it is (3) anything else, return null.  For an attribute node, return the
    entire attribute. For a text node, return it if it is between the
    milestones; otherwise return null.
  :) 
  typeswitch ($node)
    case element() return
      if ($node is $ms1) then $node
      else if ( some $n in $node/descendant::* satisfies
                ($n is $ms1 or $n is $ms2) )
      then
        element { name($node) }
                { for $i in ( $node/node() | $node/@* )
                  return dummy:milestone-chunk($ms1, $ms2, $i) }
      else if ( $node >> $ms1 and $node << $ms2 ) then $node
      else ()
    case attribute() return
      attribute { name($node) } { data($node)  }
    default return
      if ( $node >> $ms1 and $node << $ms2 ) then $node
      else ()
}; 

let $dummy := dummy:getDummyDocument()

let $docAchil := /archimedes/info[cvs_file = 'achil_propo_087_la_1545.xml']/fn:root()
let $pb184 := $docAchil//pb[@n='185']
let $pb185 := $docAchil//pb[@n='186']
let $page184 := dummy:milestone-chunk($pb184, $pb185, $docAchil//text)


return 
  (: <?xml-stylesheet type="text/xsl" href="archimedes.xsl" ?>  :)
  transform:transform($dummy, doc("/db/xsl/archimedes.xsl"), ())

(:
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html>
   <head>
     <title>Dummy</title>
   </head>
  </html>
:)