zoom: new target profile element literalTransform
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 22 Aug 2011 10:37:14 +0000 (12:37 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 22 Aug 2011 10:37:14 +0000 (12:37 +0200)
This element holds XSLT, encoded as string, for target. Only if present
and non-zero length it is considered present. This takes precedence over
transform.

NEWS
etc/config-zoom.xml
src/filter_zoom.cpp
xml/schema/filter_zoom.rnc

diff --git a/NEWS b/NEWS
index 4222a38..1a70c13 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+zoom: new target profile element literalTransform that holds XSLT
+(encoded as string) for target. Only if present and non-zero length it is
+considered present. This takes precedence over transform.
+
 --- 1.3.5 2011/08/12
 
 z3950_client: mark non-surrogate diagnostics from backend.
index dbb72f6..9887b5b 100644 (file)
            <cclmap_ti>1=title s=pw t=l,r</cclmap_ti>
            <sru>get</sru>
            <transform>dc.xsl</transform>
+           <literalTransform>&lt;?xml version="1.0" encoding="UTF-8"?>
+&lt;!--
+
+    This stylesheet expects oai/dc records
+-->
+&lt;xsl:stylesheet
+    version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
+    xmlns:dc="http://purl.org/dc/elements/1.1/"
+    xmlns:dcterms="http://purl.org/dc/terms/">
+
+ &lt;xsl:output indent="yes"
+        method="xml"
+        version="1.0"
+        encoding="UTF-8"/>
+
+  &lt;xsl:param name="medium" />
+
+  &lt;xsl:template match="/*">
+    &lt;pz:record>
+
+      &lt;pz:metadata type="id">
+        &lt;xsl:value-of select="dc:identifier"/>
+      &lt;/pz:metadata>
+
+      &lt;xsl:for-each select="dc:title">
+        &lt;pz:metadata type="title">
+          &lt;xsl:value-of select="."/>
+        &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:date">
+        &lt;pz:metadata type="date">
+         &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:subject">
+        &lt;pz:metadata type="subject">
+               &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:creator">
+             &lt;pz:metadata type="author">
+          &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:description">
+        &lt;pz:metadata type="description">
+               &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:identifier">
+        &lt;pz:metadata type="electronic-url">
+               &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dc:type">
+        &lt;pz:metadata type="medium">
+               &lt;xsl:value-of select="."/>
+             &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;xsl:for-each select="dcterms:bibliographicCitation">
+        &lt;pz:metadata type="citation">
+          &lt;xsl:value-of select="."/>
+        &lt;/pz:metadata>
+      &lt;/xsl:for-each>
+
+      &lt;pz:metadata type="medium">
+        &lt;xsl:value-of select="$medium" />
+      &lt;/pz:metadata>
+
+    &lt;/pz:record>
+  &lt;/xsl:template>
+
+  &lt;xsl:template match="text()"/>
+
+&lt;/xsl:stylesheet></literalTransform>
            <zurl>dfr.jstor.org/sru</zurl>
          </record>
 
index 533da78..ff73e19 100644 (file)
@@ -66,6 +66,7 @@ namespace metaproxy_1 {
             std::string element_set;
             std::string record_encoding;
             std::string transform_xsl_fname;
+            std::string transform_xsl_content;
             std::string urlRecipe;
             std::string contentConnector;
             bool use_turbomarc;
@@ -466,6 +467,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
             s->transform_xsl_fname = mp::xml::get_text(ptr);
         }
         else if (!strcmp((const char *) ptr->name,
+                         "literalTransform"))
+        {
+            s->transform_xsl_content = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
                          "urlRecipe"))
         {
             s->urlRecipe = mp::xml::get_text(ptr);
@@ -699,7 +705,29 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     }
         
     xsltStylesheetPtr xsp = 0;
-    if (sptr->transform_xsl_fname.length())
+    if (sptr->transform_xsl_content.length())
+    {
+        xmlDoc *xsp_doc = xmlParseMemory(sptr->transform_xsl_content.c_str(),
+                                         sptr->transform_xsl_content.length());
+        if (!xsp_doc)
+        {
+            *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+            *addinfo = (char *) odr_malloc(odr, 40);
+            sprintf(*addinfo, "xmlParseMemory failed");
+            BackendPtr b;
+            return b;
+        }
+        xsp = xsltParseStylesheetDoc(xsp_doc);
+        if (!xsp)
+        {
+            *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
+            *addinfo = odr_strdup(odr, "xsltParseStylesheetDoc failed");
+            BackendPtr b;
+            xmlFreeDoc(xsp_doc);
+            return b;
+        }
+    }
+    else if (sptr->transform_xsl_fname.length())
     {
         const char *path = 0;
 
index 95d21a0..f9e682b 100644 (file)
@@ -29,6 +29,7 @@ filter_zoom =
         element mp:requestSyntax { xsd:string }?,
         element mp:sru { xsd:string }?,
         element mp:transform { xsd:string }?,
+        element mp:literalTransform { xsd:string }?,
         element mp:urlRecipe { xsd:string }?,
         element mp:zurl { xsd:string },
         element mp:cfAuth { xsd:string }?,