(: ====================================================================== :) (: ===== FD UTILITIES ===== :) (: ====================================================================== :) (: This XQuery module contains a number of utility functions to be used in FD XQueries. XQuery agency: The European Commision XQuery version: 1.0 XQuery date: 06 January 2009 Revision: $Revision: 7707 $ Revision date: $Date: 2009-09-15 09:57:41 +0200 (ti, 15 sep 2009) $ :) xquery version "1.0"; (:===================================================================:) (: Namespace declaration :) (:===================================================================:) module namespace xmlutil = "urn:eu:com:env:dwd:converter:standard:util:1"; (:===================================================================:) (: Code lists:) (:===================================================================:) declare variable $xmlutil:errorsUrl as xs:string := "http://icm.eionet.europa.eu/schemas/dir199883ec/xquery/DWD_errors.xml"; (:==================================================================:) (: Helper functions for writing output:) (:==================================================================:) declare variable $xmlutil:LEVEL_NONE as xs:integer := 0; declare variable $xmlutil:LEVEL_ERROR as xs:integer := 1; declare variable $xmlutil:LEVEL_ERROR2 as xs:integer := 2; (:becuase of inconsistencies in writing validation:) declare variable $xmlutil:LEVEL_WARNING as xs:integer := 2; declare variable $xmlutil:LEVEL_INFO as xs:integer := 3; declare function xmlutil:buildTable($colHeaders, $tableRows ){ if (exists($tableRows) ) then ( {xmlutil:buildTableHeaderRow($colHeaders)} {$tableRows}
) else () }; (:Builds a table header row from a list of colum headers:) declare function xmlutil:buildTableHeaderRow($colHeaders){ { for $ch in $colHeaders return {$ch} } }; (:Builds a table row from a list of colum data. The row will be marked with the error given according to the error-level:) declare function xmlutil:buildTableRow($colData, $errLevel as xs:integer, $error as xs:string){ if($errLevel = $xmlutil:LEVEL_ERROR) then ( {xmlutil:buildTableCol($colData)} ) else if ($errLevel = $xmlutil:LEVEL_WARNING) then ( {xmlutil:buildTableCol($colData)} ) else ( {xmlutil:buildTableCol($colData)} ) }; (:Builds a table columns from a list of colum data.:) declare function xmlutil:buildTableCol($colData){ for $cd in $colData return {xmlutil:buildString($cd)} }; (:Gets the color corresponding to an error level:) declare function xmlutil:getErrorColor($errLevel as xs:integer) as xs:string { if($errLevel = $xmlutil:LEVEL_ERROR) then "red" else if ($errLevel = $xmlutil:LEVEL_WARNING) then "blue" else "" }; (: If the string given is empty a default string is returned. Otherwise the string itself is returned:) declare function xmlutil:buildString($var) as xs:string{ let $str:= string($var) return if(string-length($str)>0) then $str else string("-Not reported-") }; (:Builds a description text with color corresponding to the error level given:) declare function xmlutil:buildDescription($errLevel as xs:integer, $descr as xs:string){ let $color := xmlutil:getErrorColor($errLevel) let $hasColor as xs:boolean := string-length($color)>0 return if(string-length($descr)>0) then ( if($hasColor) then (

{$descr}

) else (

{$descr}

) ) else () }; (:Builds a description text with no special color:) declare function xmlutil:buildDescription($descr as xs:string){ xmlutil:buildDescription($xmlutil:LEVEL_NONE, $descr) }; (:lookup the error code in a resource file and return an error description:) declare function xmlutil:findErrorDesc($id as xs:string){ for $code in doc($xmlutil:errorsUrl )//Code let $errorID := $code/@errorID where $errorID = $id return $code/@desc }; (:Builds the return element for the validation checks:) declare function xmlutil:buildValidationReturn($name as xs:string, $root as xs:string, $value, $errorLevel as xs:integer, $checkType as xs:integer, $errorID as xs:string, $id as xs:string, $elem){ {$name} {$root} {xs:string($value)} {$errorLevel} {$checkType} {$errorID} {$id} {$elem} }; declare function xmlutil:buildValidationReturn($name as xs:string, $root as xs:string, $value as xs:string*, $checkType as xs:integer, $errorID as xs:string, $id as xs:string*, $elem){ xmlutil:buildValidationReturn($name, $root, $value, $xmlutil:LEVEL_ERROR, $checkType, $errorID, $id, $elem) }; (:==================================================================:) (: Functions for building basic output tables for different elements :) (:==================================================================:) declare function xmlutil:buildTableErrorReport($elems){ let $colHeaders := ("Element name", "Element root", "Element value", "Error Description", "RecordID") let $tableRows := (for $elem in $elems return xmlutil:buildTableRow(($elem/xmlutil:Name, $elem/xmlutil:Root ,$elem/xmlutil:Value, xmlutil:findErrorDesc($elem/xmlutil:ErrorID), $elem/xmlutil:RecordID),$elem/xmlutil:ErrorLevel, $elem/xmlutil:CheckType)) return xmlutil:buildTable($colHeaders, $tableRows) }; declare function xmlutil:codeCheckMessage(){ xmlutil:buildDescription("Code checks are carried out in the schema validation") }; declare function xmlutil:crossCheckMessage(){ xmlutil:buildDescription("Note: Schema cross-checks are carried out in ReportNet") }; declare function xmlutil:buildFileList($elems){ for $elem in $elems return
  • {string($elem/@url)}
  • }; (:==================================================================:) (: end of utilities code:) (:==================================================================:)