Allow elementset to be configured
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 18 Jun 2014 09:25:17 +0000 (11:25 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 18 Jun 2014 09:25:17 +0000 (11:25 +0200)
doc/filter_xquery.rnc
doc/xquery.xml
src/config.xml
src/metaproxy_filter_xquery.cpp

index 036c2ee..38554b7 100644 (file)
@@ -6,6 +6,10 @@ filter_xquery =
   attribute type { "xquery" },
   attribute id { xsd:NCName }?,
   attribute name { xsd:NCName }?,
   attribute type { "xquery" },
   attribute id { xsd:NCName }?,
   attribute name { xsd:NCName }?,
+  element mp:elementset {
+    attribute name { xsd:string },
+    attribute backend { xsd:string },
+  },
   element mp:script {
     attribute name { xsd:string },
   },
   element mp:script {
     attribute name { xsd:string },
   },
index 4178ad8..fec1184 100644 (file)
   <para>
    Configurable values:
    <variablelist>
   <para>
    Configurable values:
    <variablelist>
-    <varlistentry><term>&lt;script name="name"&gt;</term>
+    <varlistentry><term>&lt;elementset name="name1" backend="name2"/&gt;</term>
+     <listitem>
+      <para>
+       Specifies the elementset (name1) that triggers the transform.
+       Note that the record syntax must be XML as well.
+       The 2nd element set, name2, specifies the element set that
+       is sent to the next filter in chain (backend).
+      </para>
+     </listitem>
+    </varlistentry>
+    <varlistentry><term>&lt;script name="name"/&gt;</term>
      <listitem>
       <para>
        The full path of the XQuery script to be invoked.
      <listitem>
       <para>
        The full path of the XQuery script to be invoked.
@@ -36,7 +46,7 @@
       </para>
      </listitem>
     </varlistentry>
       </para>
      </listitem>
     </varlistentry>
-    <varlistentry><term>&lt;record name="var"&gt;</term>
+    <varlistentry><term>&lt;record name="var"/&gt;</term>
      <listitem>
       <para>
        The name of the XQUery variable where the input XML record
      <listitem>
       <para>
        The name of the XQUery variable where the input XML record
 
  <refsect1><title>EXAMPLES</title>
   <para>
 
  <refsect1><title>EXAMPLES</title>
   <para>
-   Configuration:
+   Configuration for converting MARCXML to BIBFRAME.
    <screen><![CDATA[
    <screen><![CDATA[
-    <filter type="session_shared">
-     <resultset ttl="10" max="3" restart="true"/>
-     <session ttl="30" max="100"/>
+    <filter type="xquery">
+      <elementset name="bibframe" backend="marcxml"/>
+      <script name="/usr/share/marc2bibframe/xbin/zorba3-0.xqy"/>
+      <record name="marcxmluri"/>
+      <variable name="serialization" value="rdxml"/>
+      <variable name="baseuri" value="http://base/"/>
     </filter>
 ]]>
    </screen>
     </filter>
 ]]>
    </screen>
index 2ed6842..b117c1e 100644 (file)
@@ -16,6 +16,7 @@
          <category access="false" line="true" apdu="false" />
       </filter>
       <filter type="xquery">
          <category access="false" line="true" apdu="false" />
       </filter>
       <filter type="xquery">
+       <elementset name="bibframe" backend="marcxml"/>
        <script name="/home/adam/proj/marc2bibframe/xbin/zorba3-0.xqy"/>
        <record name="marcxmluri"/>
        <variable name="serialization" value="rdxml"/>
        <script name="/home/adam/proj/marc2bibframe/xbin/zorba3-0.xqy"/>
        <record name="marcxmluri"/>
        <variable name="serialization" value="rdxml"/>
index 466164c..4864ce4 100644 (file)
@@ -59,6 +59,8 @@ namespace metaproxy_1 {
             std::string zorba_filename;
             std::string zorba_script;
             std::string zorba_record_variable;
             std::string zorba_filename;
             std::string zorba_script;
             std::string zorba_record_variable;
+            std::string elementset_input;
+            std::string elementset_output;
             Zorba *lZorba;
             XQuery_t lQuery;
         };
             Zorba *lZorba;
             XQuery_t lQuery;
         };
@@ -182,10 +184,10 @@ void yf::XQuery::process(Package &package) const
     const char *backend_schema = 0;
     const Odr_oid *backend_syntax = 0;
 
     const char *backend_schema = 0;
     const Odr_oid *backend_syntax = 0;
 
-    if (input_schema && !strcmp(input_schema, "bibframe") &&
+    if (input_schema && !strcmp(input_schema, elementset_input.c_str()) &&
         (!input_syntax || !oid_oidcmp(input_syntax, yaz_oid_recsyn_xml)))
     {
         (!input_syntax || !oid_oidcmp(input_syntax, yaz_oid_recsyn_xml)))
     {
-        backend_schema = "marcxml";
+        backend_schema = elementset_output.c_str();
         backend_syntax = yaz_oid_recsyn_xml;
     }
     else
         backend_syntax = yaz_oid_recsyn_xml;
     }
     else
@@ -319,7 +321,20 @@ void yf::XQuery::configure(const xmlNode * ptr, bool test_only,
     {
         if (ptr->type != XML_ELEMENT_NODE)
             continue;
     {
         if (ptr->type != XML_ELEMENT_NODE)
             continue;
-        if (!strcmp((const char *) ptr->name, "variable"))
+        if (!strcmp((const char *) ptr->name, "elementset"))
+        {
+            struct _xmlAttr *attr;
+            for (attr = ptr->properties; attr; attr = attr->next)
+                if (!strcmp((const char *) attr->name, "name"))
+                    elementset_input = mp::xml::get_text(attr->children);
+                else if (!strcmp((const char *) attr->name, "backend"))
+                    elementset_output = mp::xml::get_text(attr->children);
+                else
+                    throw mp::filter::FilterException(
+                        "Bad attribute " + std::string((const char *)
+                                                       attr->name));
+        }
+        else if (!strcmp((const char *) ptr->name, "variable"))
         {
             std::string name;
             std::string value;
         {
             std::string name;
             std::string value;