This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #107: deploy modules will deploy document transforms; also mo…
…dified dir structure for rest-api config and extensions
- Loading branch information
Peter Kim
committed
Jun 7, 2013
1 parent
13a6320
commit d661d45
Showing
6 changed files
with
188 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
xquery version "1.0-ml"; | ||
module namespace example = "http://marklogic.com/rest-api/transform/add-attr"; | ||
|
||
declare namespace roxy = "http://marklogic.com/roxy"; | ||
|
||
(: REST API transforms managed by Roxy must follow these conventions: | ||
1. Their filenames must reflect the name of the transform. | ||
For example, an XQuery transform named add-attr must be contained in a file named add-attr.xqy | ||
and have a module namespace of "http://marklogic.com/rest-api/transform/add-attr". | ||
2. Must declare the roxy namespace with the URI "http://marklogic.com/roxy". | ||
declare namespace roxy = "http://marklogic.com/roxy"; | ||
3. Must annotate the transform function with the transform parameters: | ||
%roxy:params("uri=xs:string", "priority=xs:int") | ||
:) | ||
|
||
declare | ||
%roxy:params("uri=xs:string", "priority=xs:int") | ||
function example:transform( | ||
$context as map:map, | ||
$params as map:map, | ||
$content as document-node() | ||
) as document-node() | ||
{ | ||
if (fn:empty($content/*)) then $content | ||
else | ||
let $value := (map:get($params,"value"),"UNDEFINED")[1] | ||
let $name := (map:get($params, "name"), "transformed")[1] | ||
let $root := $content/* | ||
return document { | ||
$root/preceding-sibling::node(), | ||
element {fn:name($root)} { | ||
attribute { fn:QName("", $name) } {$value}, | ||
$root/@*, | ||
$root/node() | ||
}, | ||
$root/following-sibling::node() | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
<!-- | ||
REST API transforms managed by Roxy must follow these conventions: | ||
1. Their filenames must reflect the name of the transform. | ||
For example, an XSL transform named add-attr must be contained in a file named add-attr.xslt. | ||
2. Must annotate the file with the transform parameters in an XML comment: | ||
%roxy:params("uri=xs:string", "priority=xs:int") | ||
--> | ||
|
||
<!-- %roxy:params("uri=xs:string", "priority=xs:int") --> | ||
<xsl:stylesheet version="2.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:example="http://marklogic.com/rest-api/example/transform" | ||
xmlns:map="http://marklogic.com/xdmp/map"> | ||
<xsl:param name="context" as="map:map"/> | ||
<xsl:param name="params" as="map:map"/> | ||
<xsl:template match="/*"> | ||
<xsl:copy> | ||
<xsl:attribute | ||
name='{(map:get($params,"name"),"transformed")[1]}' | ||
select='(map:get($params,"value"),"UNDEFINED")[1]'/> | ||
<xsl:copy-of select="@*"/> | ||
<xsl:copy-of select="node()"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
</xsl:stylesheet> |