AdrDb2

Adressen

Adressen

debug



Name (Ansprechform)
Familie
Vorname
2. Name
Titel
Kürzel
Bild (OID?)
Geburtstag
Organisation
Strasse
Ort
Plz
Kürzel
Geburtstag
Organisation
(let ((handle (lambda (node) (let ((ff (form-field (gi node) (current-node)))) (if (node-list-empty? ff) node ff))))) (make element gi: 'Description ns: (string->symbol "http://www.w3.org/1999/02/22-rdf-syntax-ns#") attributes: `((xmlns rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#") (xmlns "http://www.w3.org/2001/vcard-rdf/3.0#") (about ,(oid->string (msg 'dc-creator)))) (node-list-map (lambda (node) (cond ((match-element? 'n node) (make element gi: 'n (node-list-map handle (children node)))) ((match-element? 'adr node) (make element gi: 'adr (node-list-map handle (children node)))) ;; All form fields (else (handle node)))) ;; The children of the root of the style sheet. ((sxpath '(emptyEntry Description *)) (grove-root (current-node)))))) (node-list-first (xsl-variable "new-entry"))

Source code:

<xsl:stylesheet xmlns:addrdb="urn:addrdb" xmlns:d="http://www.askemos.org/2000/NameSpaceDSSSL" xmlns:mind="http://www.askemos.org/2000/CoreAPI" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--

This is how we define our data structure: write down an example entry.

-->
 <addrdb:emptyEntry>
  <rdf:Description xmlns="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" about="A00000000000000000000000000000001">
<!-- formatted name -->
   <fn></fn>
   <n>
    <surname></surname>
    <firstname></firstname>
    <middlename></middlename>
    <honorific></honorific>
   </n>
   <nickname></nickname>
   <photo resource="xpath value (prefered &apos;/oid&apos; ) "></photo>
   <bday></bday>
   <adr>
    <affilation></affilation>
    <street></street>
    <city></city>
    <zip></zip>
   </adr>
  </rdf:Description>
 </addrdb:emptyEntry>
<!--

Default the current (edit cursor) record to the reader if no "about"
field is in the input form.

-->
 <xsl:variable name="current">
  <d:copy-of select="
 (let* ((about-field (form-field &apos;about (current-node)))
        (about (me (if (node-list-empty? about-field)
                       (oid-&gt;string (msg &apos;dc-creator))
                       (data about-field)))))
   
   (or (and about (fetch about))
       ((sxpath &apos;(emptyEntry *)) (grove-root (current-node)))))
"></d:copy-of>
 </xsl:variable>
 <xsl:template match="request[@type=&quot;read&quot;]">
  <xsl:choose>
<!--

If the next destination step indicates the oid of some entry, forward
to the entry.

-->
   <d:when test="(pair? (msg &apos;destination))">
    <mind:forward></mind:forward>
   </d:when>
<!--

Standard debug interface for development and maintainence available
for the creator only.

-->
   <d:when test="(and (is-meta-form? msg) (service-level (me &apos;dc-creator)))">
    <d:copy-of select="(message-body (metaview me msg))"></d:copy-of>
   </d:when>
   <xsl:otherwise>
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>Adressen</title>
      <meta content="text/html" http-equiv="Content-Type"></meta>
     </head>
     <body bgcolor="white">
      <h1>Adressen</h1>
<!-- Again the creator only will get this link. -->
      <d:if test="(service-level (me &apos;dc-creator))">
       <p>
        <d:a d:href="
(read-locator (msg &apos;location-format)
  (list body: &quot;xmlns=mind&quot; (me &apos;get &apos;id)))
">debug</d:a>
       </p>
      </d:if>
      <d:form action="&apos;()" method="get">
       <p>
        <input name="search" type="text"></input>
        <input type="submit" value="Suche"></input>
       </p>
      </d:form>
      <xsl:choose>
       <d:when test="
(&gt; (string-length (data (form-field &apos;search (current-node)))) 2)
">
<!-- Search results only with at leat 3 characters of search string. -->
        <p>
<!-- fold-links yields a function with two parameters, a
combinator and an initial value.  The combinator is applied once for
each link to the link name and the accumulated inital value, i.e., it
returns the "new" initial value.

pcre creates a match function for a perl regualr expression.

fetch gets the entry from the link, which is matched by the search and
if a match is found, it's inserted into the result.

 -->
         <d:for-each select="
  (let ((search (pcre (data (form-field &apos;search (current-node))))))
    ((me &apos;fold-links)
     (lambda (name i) (if (search (fetch name)) (cons name i) i))
     &apos;()))
">
<!--  The link is prepared to display the detailed entry. -->
          <d:a d:href="(read-locator (msg &apos;location-format)
  (list body: (string-append &quot;about=&quot; (data (current-node)))  (me &apos;get &apos;id)))">
           <d:copy-of select="((sxpath &apos;(fn)) (fetch (me (current-node))))"></d:copy-of>
          </d:a>
          <br></br>
         </d:for-each>
        </p>
       </d:when>
<!--

The owner of an entry gets an input form to change the entry.

-->
       <d:when test="
(eq? (string-&gt;oid (attribute-string &apos;about (node-list-first (xsl-variable &quot;current&quot;)))) (msg &apos;dc-creator))
;; (service-level (string-&gt;oid (attribute-string &apos;about (node-list-first (xsl-variable &quot;current&quot;) ))))
">
        <d:form action="&apos;()" method="post">
         <table bgcolor="silver" border="0">
          <tr>
           <td>Name (Ansprechform)</td>
           <td>
            <d:input name="fn" type="text" d:value="(data ((sxpath &apos;(fn)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Familie</td>
           <td>
            <d:input name="surname" type="text" d:value="(data ((sxpath &apos;(n surname)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Vorname</td>
           <td>
            <d:input name="firstname" type="text" d:value="(data ((sxpath &apos;(n firstname)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>2. Name</td>
           <td>
            <d:input name="middlename" type="text" d:value="(data ((sxpath &apos;(n middlename)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Titel</td>
           <td>
            <d:input name="honorific" type="text" d:value="(data ((sxpath &apos;(n honorific)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Kürzel</td>
           <td>
            <d:input name="nickname" type="text" d:value="(data ((sxpath &apos;(nickname)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Bild (OID)</td>
           <td>
            <d:input name="photo" type="text" d:value="(data ((sxpath &apos;(photo)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Geburtstag</td>
           <td>
            <d:input name="bday" type="text" d:value="(data ((sxpath &apos;(bday)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Organisation</td>
           <td>
            <d:input name="affilation" type="text" d:value="(data ((sxpath &apos;(adr affilation)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Strasse</td>
           <td>
            <d:input name="street" type="text" d:value="(data ((sxpath &apos;(adr street)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Ort
</td>
           <td>
            <d:input name="city" type="text" d:value="(data ((sxpath &apos;(adr city)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>Plz</td>
           <td>
            <d:input name="zip" type="text" d:value="(data ((sxpath &apos;(adr zip)) (xsl-variable &quot;current&quot;)))"></d:input>
           </td>
          </tr>
          <tr>
           <td>
            <d:input type="submit" value="eintragen"></d:input>
            <d:input name="action" type="hidden" value="save"></d:input>
           </td>
           <td>
            <small>
             <code>
              <d:copy-of select="(attribute-string &apos;about (node-list-first (xsl-variable &quot;current&quot;) ))"></d:copy-of>
             </code>
            </small>
           </td>
          </tr>
         </table>
        </d:form>
       </d:when>
<!--

Show the name for everybody else.

-->
       <xsl:otherwise>
        <table bgcolor="silver" border="0">
         <tr>
          <td colspan="2">
           <d:copy-of select="
(literal
 (data ((sxpath &apos;(n honorific)) (xsl-variable &quot;current&quot;)))
 &quot; &quot;
 (data ((sxpath &apos;(fn)) (xsl-variable &quot;current&quot;))))"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td>Kürzel</td>
          <td>
           <d:copy-of select="(children ((sxpath &apos;(nickname)) (xsl-variable &quot;current&quot;)))"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td>Geburtstag</td>
          <td>
           <d:copy-of select="(children ((sxpath &apos;(bday)) (xsl-variable &quot;current&quot;)))"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td>Organisation</td>
          <td>
           <d:copy-of select="(children ((sxpath &apos;(adr affilation)) (xsl-variable &quot;current&quot;)))"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td colspan="2">
           <d:copy-of select="(children ((sxpath &apos;(adr street)) (xsl-variable &quot;current&quot;)))"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td colspan="2">
           <d:copy-of select="
(node-list
  (children ((sxpath &apos;(adr zip)) (xsl-variable &quot;current&quot;)))
  (literal &quot; &quot;)
  (children ((sxpath &apos;(adr city)) (xsl-variable &quot;current&quot;))))
"></d:copy-of>
          </td>
         </tr>
         <tr>
          <td colspan="2">
           <small>
            <code>
             <d:copy-of select="(attribute-string &apos;about (node-list-first (xsl-variable &quot;current&quot;) ))"></d:copy-of>
            </code>
           </small>
          </td>
         </tr>
        </table>
       </xsl:otherwise>
      </xsl:choose>
     </body>
    </html>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="request[@type=&quot;write&quot;]">
  <xsl:variable name="new-entry">
   <d:copy-of select="#CONTENT">
     (let ((handle (lambda (node)
                     (let ((ff (form-field (gi node) (current-node))))
                       (if (node-list-empty? ff) node ff)))))
      (make element
        gi: 'Description ns: (string-&gt;symbol "<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;)">http://www.w3.org/1999/02/22-rdf-syntax-ns#")</a>
        attributes: `((xmlns rdf "<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;)">http://www.w3.org/1999/02/22-rdf-syntax-ns#")</a>
                      (xmlns "<a href="http://www.w3.org/2001/vcard-rdf/3.0#&quot;)">http://www.w3.org/2001/vcard-rdf/3.0#")</a>
                      (about ,(oid-&gt;string (msg 'dc-creator))))
        (node-list-map
         (lambda (node)
           (cond
            ((match-element? 'n node)
             (make element gi: 'n
               (node-list-map handle (children node))))
            ((match-element? 'adr node)
             (make element gi: 'adr
               (node-list-map handle (children node))))
            ;; All form fields
            (else (handle node))))
         ;; The children of the root of the style sheet.
         ((sxpath '(emptyEntry Description *)) (grove-root (current-node))))))
     </d:copy-of>
  </xsl:variable>
  <xsl:choose>
<!--

Support the standard debug interface.

-->
   <d:when test="(and (is-meta-form? msg) (service-level (me &apos;dc-creator)))">
    <d:copy-of select="(message-body (metactrl me msg))"></d:copy-of>
   </d:when>
<!--

Chech the ownership of the entry.

-->
   <d:when test="(not (or (service-level (string-&gt;oid (attribute-string &apos;about (node-list-first (xsl-variable &quot;new-entry&quot;) )))) (error &quot;privat property&quot;)))"></d:when>
<!--

OK, change the entry.

-->
   <xsl:otherwise>
    <mind:reply>
     <d:copy-of select="(grove-root (current-node))"></d:copy-of>
     <mind:link>
      <xsl:attribute name="name">
       <d:copy-of select="
(attribute-string &apos;about (node-list-first (xsl-variable &quot;new-entry&quot;)))"></d:copy-of>
      </xsl:attribute>
      <mind:new action="Af051fe01ba259f25aae185d500b3d6a2" protection="Af051fe01ba259f25aae185d500b3d6a2">
<!--
        <xsl:attribute name="initialize">true</xsl:attribute>-->
       <d:copy-of select="#CONTENT">
(node-list-first (xsl-variable "new-entry"))
</d:copy-of>
      </mind:new>
     </mind:link>
    </mind:reply>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

Diese Seite findet man von: overview, .




Letzte Modifikation: Thu, 26 Jun 2003 19:34:39 +0200

Autor(en):

Dokument Nummer A67bb0753e1676f81983e0ecf3a15b391 geliefert an public um Thu, 20 Nov 2008 11:44:12 +0100