Bug fix: node instead of text for last update field

xquery version "1.0-ml";

declare namespace c = "http://marklogic.com/program360/contract";
declare namespace ism = "urn:us:gov:ic:ism";
declare namespace p = "http://schemas.openxmlformats.org/presentationml/2006/main";
declare namespace a="http://schemas.openxmlformats.org/drawingml/2006/main";
declare namespace r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
declare namespace sch = "http://marklogic.com/program360/schedule";

declare variable $PROJECT-URI as xs:string external;

declare function local:get-color-code($val){
  let $map := map:map()
  let $put := (map:put($map, "green","00B050"),
  map:put($map, "yellow","FFFF00"),
  map:put($map, "red","FF0000"))
  return
    <a:tc>
      <a:txBody>
        <a:bodyPr/>
        <a:lstStyle/>
        <a:p>
          <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
        </a:p>
      </a:txBody>
      <a:tcPr>
        <a:solidFill>
          <a:srgbClr val="{map:get($map,$val)}"/>
        </a:solidFill>
      </a:tcPr>
    </a:tc>
};
let $project := fn:doc($PROJECT-URI)
let $classification := $project/*:component/*:name/@*:classification
let $slide :=
  <p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <p:cSld>
      <p:spTree>
        <p:nvGrpSpPr>
          <p:cNvPr id="1" name=""/>
          <p:cNvGrpSpPr/>
          <p:nvPr/>
        </p:nvGrpSpPr>
        <p:grpSpPr>
          <a:xfrm>
            <a:off x="0" y="0"/>
            <a:ext cx="0" cy="0"/>
            <a:chOff x="0" y="0"/>
            <a:chExt cx="0" cy="0"/>
          </a:xfrm>
        </p:grpSpPr>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="2" name="title"/>
            <p:cNvSpPr>
              <a:spLocks noGrp="1"/>
            </p:cNvSpPr>
            <p:nvPr>
              <p:ph type="ctrTitle"/>
            </p:nvPr>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="990600" y="228600"/>
              <a:ext cx="7772400" cy="614728"/>
            </a:xfrm>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr>
              <a:noAutofit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="3600"/>
                <a:t>{fn:concat(fn:concat("(",$classification),") ")} {$project/*:component/*:name/text()}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="3600"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:graphicFrame>
          <p:nvGraphicFramePr>
            <p:cNvPr id="11" name="Table 10"/>
            <p:cNvGraphicFramePr>
              <a:graphicFrameLocks noGrp="1"/>
            </p:cNvGraphicFramePr>
            <p:nvPr>
              <p:extLst>
                <p:ext uri="{{D42A27DB-BD31-4B8C-83A1-F6EECF244321}}">
                  <p14:modId val="3556452996" xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"/>
                </p:ext>
              </p:extLst>
            </p:nvPr>
          </p:nvGraphicFramePr>
          <p:xfrm>
            <a:off x="4572000" y="3631220"/>
            <a:ext cx="4419601" cy="940780"/>
          </p:xfrm>
          <a:graphic>
            <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">
              <a:tbl>
                <a:tblPr bandRow="1" firstRow="1">
                  <a:tableStyleId>{{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}}</a:tableStyleId>
                </a:tblPr>
                <a:tblGrid>
                  <a:gridCol w="533400"/>
                  <a:gridCol w="685800"/>
                  <a:gridCol w="914400"/>
                  <a:gridCol w="665481"/>
                  <a:gridCol w="589280"/>
                  <a:gridCol w="399869"/>
                  <a:gridCol w="631371"/>
                </a:tblGrid>
                <a:tr h="304800">
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Burn</a:t>
                        </a:r>
                        <a:r>
                          <a:rPr baseline="0" dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>rate</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Schedule</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Performance</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Funding</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Sustain</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Risk</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Issues</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                </a:tr>
                <a:tr h="544540">
                  {
                    local:get-color-code($project/*:component/*:metrics/*:burn-rate/text()),
                    local:get-color-code($project/*:component/*:metrics/*:schedule/text()),
                    local:get-color-code($project/*:component/*:metrics/*:performance/text()),
                    local:get-color-code($project/*:component/*:metrics/*:funding/text()),
                    local:get-color-code($project/*:component/*:metrics/*:sustain/text()),
                    local:get-color-code($project/*:component/*:metrics/*:risk/text()),
                    local:get-color-code($project/*:component/*:metrics/*:issues/text())
                  }
                </a:tr>
              </a:tbl>
            </a:graphicData>
          </a:graphic>
        </p:graphicFrame>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="7" name="last-update"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="7010400" y="136071"/>
              <a:ext cx="1888350" cy="381000"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr lang="en-US" smtClean="0"/>
                <a:t>{$project/*:component/*:last-update/text()}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:cxnSp>
          <p:nvCxnSpPr>
            <p:cNvPr id="10" name="Straight Connector 9"/>
            <p:cNvCxnSpPr/>
            <p:nvPr/>
          </p:nvCxnSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="1283732"/>
              <a:ext cx="8915400" cy="11668"/>
            </a:xfrm>
            <a:prstGeom prst="line">
              <a:avLst/>
            </a:prstGeom>
            <a:ln w="28575"/>
          </p:spPr>
          <p:style>
            <a:lnRef idx="1">
              <a:schemeClr val="accent1"/>
            </a:lnRef>
            <a:fillRef idx="0">
              <a:schemeClr val="accent1"/>
            </a:fillRef>
            <a:effectRef idx="0">
              <a:schemeClr val="accent1"/>
            </a:effectRef>
            <a:fontRef idx="minor">
              <a:schemeClr val="tx1"/>
            </a:fontRef>
          </p:style>
        </p:cxnSp>
        <p:grpSp>
          <p:nvGrpSpPr>
            <p:cNvPr id="39" name="Group 38"/>
            <p:cNvGrpSpPr/>
            <p:nvPr/>
          </p:nvGrpSpPr>
          <p:grpSpPr>
            <a:xfrm>
              <a:off x="0" y="914400"/>
              <a:ext cx="8991600" cy="5791200"/>
              <a:chOff x="0" y="914400"/>
              <a:chExt cx="8991600" cy="5791200"/>
            </a:xfrm>
          </p:grpSpPr>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="8" name="Straight Connector 7"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="76200" y="914400"/>
                <a:ext cx="8915400" cy="0"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
          <p:sp>
            <p:nvSpPr>
              <p:cNvPr id="9" name="requirement"/>
              <p:cNvSpPr txBox="1"/>
              <p:nvPr/>
            </p:nvSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="0" y="914400"/>
                <a:ext cx="8991600" cy="369332"/>
              </a:xfrm>
              <a:prstGeom prst="rect">
                <a:avLst/>
              </a:prstGeom>
              <a:noFill/>
            </p:spPr>
            <p:txBody>
              <a:bodyPr rtlCol="0" wrap="square">
                <a:spAutoFit/>
              </a:bodyPr>
              <a:lstStyle/>
              <a:p>
                <a:r>
                  <a:rPr dirty="0" lang="en-US" smtClean="0"/>
                  <a:t>Requirement: {$project/*:component/*:requirement/text()}</a:t>
                </a:r>
                <a:endParaRPr dirty="0" lang="en-US"/>
              </a:p>
            </p:txBody>
          </p:sp>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="13" name="Straight Connector 12"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="4495800" y="1295400"/>
                <a:ext cx="0" cy="5410200"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="15" name="Straight Connector 14"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="114300" y="3521018"/>
                <a:ext cx="8839200" cy="0"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
        </p:grpSp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="27" name="description-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="1339334"/>
              <a:ext cx="4419600" cy="369332"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0" u="sng"/>
                <a:t>PROJECT DESCRIPTION:</a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US" u="sng"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="28" name="description"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4724400" y="1828800"/>
              <a:ext cx="4174350" cy="584775"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:pPr indent="-285750" marL="285750">
                <a:buFont charset="0" pitchFamily="34" typeface="Arial"/>
                <a:buChar char="•"/>
              </a:pPr>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>{$project/*:component/*:description/text()}</a:t>
              </a:r>
            </a:p>
            <a:p>
              <a:endParaRPr dirty="0" lang="en-US" sz="1600"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="29" name="sponsor"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="3826209"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>SPONSOR: {fn:string-join($project/*:component//*:sponsor/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="30" name="ic-mission-partners"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4599486"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>IC MISSION PARTNERS: {fn:string-join($project/*:component//*:partner/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="31" name="customer"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4197106"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>CUSTOMER: {fn:string-join($project/*:component//*:customer/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="32" name="ic-transition-agent"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4957932"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>TRANSITION AGENT: {fn:string-join($project/*:component//*:transition-agent/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="33" name="contract-name"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="5339715"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>Contract Name:{$project/*:component//*:contract/*:name/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="34" name="prime"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="5709047"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>PRIME: {$project/*:component//*:prime/text()}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="35" name="interagency-agreement"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="6013847"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>INTERAGENCY AGREEMENT: {$project/*:component//*:interagency-agreement/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="36" name="security-classification-guide"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="6321623"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>SECURITY CLASSIFICATION GUIDE: {$project/*:component//*:security-classification-guide/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="37" name="project-status-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4533900" y="4773266"/>
              <a:ext cx="3429000" cy="369332"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0" u="sng"/>
                <a:t>PROJECT STATUS</a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US" u="sng"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="38" name="project-status"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="5096470"/>
              <a:ext cx="3048000" cy="923330"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            {
              for $status in $project/*:component/*:status
              return
                <a:p>
                  <a:pPr indent="-285750" marL="285750">
                    <a:buFont charset="0" pitchFamily="34" typeface="Arial"/>
                    <a:buChar char="•"/>
                  </a:pPr>
                  <a:r>
                    <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1100"/>
                    <a:t>{fn:concat(fn:concat(fn:concat('(',fn:data($status/@*:classification)),')'), $status/text())}</a:t>
                  </a:r>
                </a:p>
            }
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="40" name="funding-type-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="6172200"/>
              <a:ext cx="1676400" cy="383977"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0"/>
                <a:t>FUNDING TYPE: </a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="41" name="funding-type"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="6248400" y="6187276"/>
              <a:ext cx="2628900" cy="491581"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0"/>
                <a:t>{('('||fn:data($project/*:component/*:funding/@*:classification)||')' || ' '|| $project/*:component/*:funding/*:type/text() || ': ' || $project/*:component/*:funding/*:fiscal-year/text() || ' $' || $project/*:component/*:funding/*:status/text())}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
      </p:spTree>
      <p:extLst>
        <p:ext uri="{{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}}">
          <p14:creationId val="3520663452" xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"/>
        </p:ext>
      </p:extLst>
    </p:cSld>
    <p:clrMapOvr>
      <a:masterClrMapping/>
    </p:clrMapOvr>
    <p:timing>
      <p:tnLst>
        <p:par>
          <p:cTn dur="indefinite" id="1" nodeType="tmRoot" restart="never"/>
        </p:par>
      </p:tnLst>
    </p:timing>
  </p:sld>
return document { $slide }

xquery version "1.0-ml";

declare namespace c = "http://marklogic.com/program360/contract";
declare namespace ism = "urn:us:gov:ic:ism";
declare namespace p = "http://schemas.openxmlformats.org/presentationml/2006/main";
declare namespace a="http://schemas.openxmlformats.org/drawingml/2006/main";
declare namespace r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
declare namespace sch = "http://marklogic.com/program360/schedule";

declare variable $PROJECT-URI as xs:string external;

declare function local:get-color-code($val){
  let $map := map:map()
  let $put := (map:put($map, "green","00B050"),
  map:put($map, "yellow","FFFF00"),
  map:put($map, "red","FF0000"))
  return
    <a:tc>
      <a:txBody>
        <a:bodyPr/>
        <a:lstStyle/>
        <a:p>
          <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
        </a:p>
      </a:txBody>
      <a:tcPr>
        <a:solidFill>
          <a:srgbClr val="{map:get($map,$val)}"/>
        </a:solidFill>
      </a:tcPr>
    </a:tc>
};
let $project := fn:doc($PROJECT-URI)
let $classification := $project/*:component/*:name/@*:classification
let $slide :=
  <p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <p:cSld>
      <p:spTree>
        <p:nvGrpSpPr>
          <p:cNvPr id="1" name=""/>
          <p:cNvGrpSpPr/>
          <p:nvPr/>
        </p:nvGrpSpPr>
        <p:grpSpPr>
          <a:xfrm>
            <a:off x="0" y="0"/>
            <a:ext cx="0" cy="0"/>
            <a:chOff x="0" y="0"/>
            <a:chExt cx="0" cy="0"/>
          </a:xfrm>
        </p:grpSpPr>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="2" name="title"/>
            <p:cNvSpPr>
              <a:spLocks noGrp="1"/>
            </p:cNvSpPr>
            <p:nvPr>
              <p:ph type="ctrTitle"/>
            </p:nvPr>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="990600" y="228600"/>
              <a:ext cx="7772400" cy="614728"/>
            </a:xfrm>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr>
              <a:noAutofit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="3600"/>
                <a:t>{fn:concat(fn:concat("(",$classification),") ")} {$project/*:component/*:name/text()}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="3600"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:graphicFrame>
          <p:nvGraphicFramePr>
            <p:cNvPr id="11" name="Table 10"/>
            <p:cNvGraphicFramePr>
              <a:graphicFrameLocks noGrp="1"/>
            </p:cNvGraphicFramePr>
            <p:nvPr>
              <p:extLst>
                <p:ext uri="{{D42A27DB-BD31-4B8C-83A1-F6EECF244321}}">
                  <p14:modId val="3556452996" xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"/>
                </p:ext>
              </p:extLst>
            </p:nvPr>
          </p:nvGraphicFramePr>
          <p:xfrm>
            <a:off x="4572000" y="3631220"/>
            <a:ext cx="4419601" cy="940780"/>
          </p:xfrm>
          <a:graphic>
            <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">
              <a:tbl>
                <a:tblPr bandRow="1" firstRow="1">
                  <a:tableStyleId>{{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}}</a:tableStyleId>
                </a:tblPr>
                <a:tblGrid>
                  <a:gridCol w="533400"/>
                  <a:gridCol w="685800"/>
                  <a:gridCol w="914400"/>
                  <a:gridCol w="665481"/>
                  <a:gridCol w="589280"/>
                  <a:gridCol w="399869"/>
                  <a:gridCol w="631371"/>
                </a:tblGrid>
                <a:tr h="304800">
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Burn</a:t>
                        </a:r>
                        <a:r>
                          <a:rPr baseline="0" dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>rate</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Schedule</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Performance</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Funding</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Sustain</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Risk</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                  <a:tc>
                    <a:txBody>
                      <a:bodyPr/>
                      <a:lstStyle/>
                      <a:p>
                        <a:r>
                          <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1000"/>
                          <a:t>Issues</a:t>
                        </a:r>
                        <a:endParaRPr dirty="0" lang="en-US" sz="1000"/>
                      </a:p>
                    </a:txBody>
                    <a:tcPr/>
                  </a:tc>
                </a:tr>
                <a:tr h="544540">
                  {
                    local:get-color-code($project/*:component/*:metrics/*:burn-rate/text()),
                    local:get-color-code($project/*:component/*:metrics/*:schedule/text()),
                    local:get-color-code($project/*:component/*:metrics/*:performance/text()),
                    local:get-color-code($project/*:component/*:metrics/*:funding/text()),
                    local:get-color-code($project/*:component/*:metrics/*:sustain/text()),
                    local:get-color-code($project/*:component/*:metrics/*:risk/text()),
                    local:get-color-code($project/*:component/*:metrics/*:issues/text())
                  }
                </a:tr>
              </a:tbl>
            </a:graphicData>
          </a:graphic>
        </p:graphicFrame>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="7" name="last-update"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="7010400" y="136071"/>
              <a:ext cx="1888350" cy="381000"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr lang="en-US" smtClean="0"/>
                <a:t>{$project/*:component/*:last-update}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:cxnSp>
          <p:nvCxnSpPr>
            <p:cNvPr id="10" name="Straight Connector 9"/>
            <p:cNvCxnSpPr/>
            <p:nvPr/>
          </p:nvCxnSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="1283732"/>
              <a:ext cx="8915400" cy="11668"/>
            </a:xfrm>
            <a:prstGeom prst="line">
              <a:avLst/>
            </a:prstGeom>
            <a:ln w="28575"/>
          </p:spPr>
          <p:style>
            <a:lnRef idx="1">
              <a:schemeClr val="accent1"/>
            </a:lnRef>
            <a:fillRef idx="0">
              <a:schemeClr val="accent1"/>
            </a:fillRef>
            <a:effectRef idx="0">
              <a:schemeClr val="accent1"/>
            </a:effectRef>
            <a:fontRef idx="minor">
              <a:schemeClr val="tx1"/>
            </a:fontRef>
          </p:style>
        </p:cxnSp>
        <p:grpSp>
          <p:nvGrpSpPr>
            <p:cNvPr id="39" name="Group 38"/>
            <p:cNvGrpSpPr/>
            <p:nvPr/>
          </p:nvGrpSpPr>
          <p:grpSpPr>
            <a:xfrm>
              <a:off x="0" y="914400"/>
              <a:ext cx="8991600" cy="5791200"/>
              <a:chOff x="0" y="914400"/>
              <a:chExt cx="8991600" cy="5791200"/>
            </a:xfrm>
          </p:grpSpPr>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="8" name="Straight Connector 7"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="76200" y="914400"/>
                <a:ext cx="8915400" cy="0"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
          <p:sp>
            <p:nvSpPr>
              <p:cNvPr id="9" name="requirement"/>
              <p:cNvSpPr txBox="1"/>
              <p:nvPr/>
            </p:nvSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="0" y="914400"/>
                <a:ext cx="8991600" cy="369332"/>
              </a:xfrm>
              <a:prstGeom prst="rect">
                <a:avLst/>
              </a:prstGeom>
              <a:noFill/>
            </p:spPr>
            <p:txBody>
              <a:bodyPr rtlCol="0" wrap="square">
                <a:spAutoFit/>
              </a:bodyPr>
              <a:lstStyle/>
              <a:p>
                <a:r>
                  <a:rPr dirty="0" lang="en-US" smtClean="0"/>
                  <a:t>Requirement: {$project/*:component/*:requirement/text()}</a:t>
                </a:r>
                <a:endParaRPr dirty="0" lang="en-US"/>
              </a:p>
            </p:txBody>
          </p:sp>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="13" name="Straight Connector 12"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="4495800" y="1295400"/>
                <a:ext cx="0" cy="5410200"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
          <p:cxnSp>
            <p:nvCxnSpPr>
              <p:cNvPr id="15" name="Straight Connector 14"/>
              <p:cNvCxnSpPr/>
              <p:nvPr/>
            </p:nvCxnSpPr>
            <p:spPr>
              <a:xfrm>
                <a:off x="114300" y="3521018"/>
                <a:ext cx="8839200" cy="0"/>
              </a:xfrm>
              <a:prstGeom prst="line">
                <a:avLst/>
              </a:prstGeom>
              <a:ln w="28575"/>
            </p:spPr>
            <p:style>
              <a:lnRef idx="1">
                <a:schemeClr val="accent1"/>
              </a:lnRef>
              <a:fillRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:fillRef>
              <a:effectRef idx="0">
                <a:schemeClr val="accent1"/>
              </a:effectRef>
              <a:fontRef idx="minor">
                <a:schemeClr val="tx1"/>
              </a:fontRef>
            </p:style>
          </p:cxnSp>
        </p:grpSp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="27" name="description-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="1339334"/>
              <a:ext cx="4419600" cy="369332"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0" u="sng"/>
                <a:t>PROJECT DESCRIPTION:</a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US" u="sng"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="28" name="description"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4724400" y="1828800"/>
              <a:ext cx="4174350" cy="584775"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:pPr indent="-285750" marL="285750">
                <a:buFont charset="0" pitchFamily="34" typeface="Arial"/>
                <a:buChar char="•"/>
              </a:pPr>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>{$project/*:component/*:description/text()}</a:t>
              </a:r>
            </a:p>
            <a:p>
              <a:endParaRPr dirty="0" lang="en-US" sz="1600"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="29" name="sponsor"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="3826209"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>SPONSOR: {fn:string-join($project/*:component//*:sponsor/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="30" name="ic-mission-partners"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4599486"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>IC MISSION PARTNERS: {fn:string-join($project/*:component//*:partner/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="31" name="customer"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4197106"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>CUSTOMER: {fn:string-join($project/*:component//*:customer/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="32" name="ic-transition-agent"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="4957932"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>TRANSITION AGENT: {fn:string-join($project/*:component//*:transition-agent/text(),', ')}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="33" name="contract-name"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="5339715"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>Contract Name:{$project/*:component//*:contract/*:name/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="34" name="prime"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="5709047"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>PRIME: {$project/*:component//*:prime/text()}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="35" name="interagency-agreement"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="6013847"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>INTERAGENCY AGREEMENT: {$project/*:component//*:interagency-agreement/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="36" name="security-classification-guide"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="76200" y="6321623"/>
              <a:ext cx="4267200" cy="307777"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1400"/>
                <a:t>SECURITY CLASSIFICATION GUIDE: {$project/*:component//*:security-classification-guide/text()} </a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US" sz="1400"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="37" name="project-status-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4533900" y="4773266"/>
              <a:ext cx="3429000" cy="369332"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0" u="sng"/>
                <a:t>PROJECT STATUS</a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US" u="sng"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="38" name="project-status"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="5096470"/>
              <a:ext cx="3048000" cy="923330"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            {
              for $status in $project/*:component/*:status
              return
                <a:p>
                  <a:pPr indent="-285750" marL="285750">
                    <a:buFont charset="0" pitchFamily="34" typeface="Arial"/>
                    <a:buChar char="•"/>
                  </a:pPr>
                  <a:r>
                    <a:rPr dirty="0" lang="en-US" smtClean="0" sz="1100"/>
                    <a:t>{fn:concat(fn:concat(fn:concat('(',fn:data($status/@*:classification)),')'), $status/text())}</a:t>
                  </a:r>
                </a:p>
            }
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="40" name="funding-type-label"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="4572000" y="6172200"/>
              <a:ext cx="1676400" cy="383977"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr b="1" dirty="0" lang="en-US" smtClean="0"/>
                <a:t>FUNDING TYPE: </a:t>
              </a:r>
              <a:endParaRPr b="1" dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="41" name="funding-type"/>
            <p:cNvSpPr txBox="1"/>
            <p:nvPr/>
          </p:nvSpPr>
          <p:spPr>
            <a:xfrm>
              <a:off x="6248400" y="6187276"/>
              <a:ext cx="2628900" cy="491581"/>
            </a:xfrm>
            <a:prstGeom prst="rect">
              <a:avLst/>
            </a:prstGeom>
            <a:noFill/>
          </p:spPr>
          <p:txBody>
            <a:bodyPr rtlCol="0" wrap="square">
              <a:spAutoFit/>
            </a:bodyPr>
            <a:lstStyle/>
            <a:p>
              <a:r>
                <a:rPr dirty="0" lang="en-US" smtClean="0"/>
                <a:t>{('('||fn:data($project/*:component/*:funding/@*:classification)||')' || ' '|| $project/*:component/*:funding/*:type/text() || ': ' || $project/*:component/*:funding/*:fiscal-year/text() || ' $' || $project/*:component/*:funding/*:status/text())}</a:t>
              </a:r>
              <a:endParaRPr dirty="0" lang="en-US"/>
            </a:p>
          </p:txBody>
        </p:sp>
      </p:spTree>
      <p:extLst>
        <p:ext uri="{{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}}">
          <p14:creationId val="3520663452" xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main"/>
        </p:ext>
      </p:extLst>
    </p:cSld>
    <p:clrMapOvr>
      <a:masterClrMapping/>
    </p:clrMapOvr>
    <p:timing>
      <p:tnLst>
        <p:par>
          <p:cTn dur="indefinite" id="1" nodeType="tmRoot" restart="never"/>
        </p:par>
      </p:tnLst>
    </p:timing>
  </p:sld>
return document { $slide }


removed debugging fields from facility select stored menu

import module namespace functx = "http://www.functx.com";
declare namespace csd = "urn:ihe:iti:csd:2013";
declare variable $careServicesRequest as item() external;

let $t_top_orgid  :=  $careServicesRequest/query[@name = 'orgid']/text()
let $top_org :=  (/csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $t_top_orgid])[1]

let $selected_text := $careServicesRequest/query[@name = 'input']/text()
(:
let $selections := $careServicesRequest/values/item[./pair[@name = 'label' and ./text() = 'facilityselection']]
let $selected_text :=
  if (count($selections) > 0)
  then
    let $max_time := max(for $time in $selections/pair[@name='time'] return xs:dateTime($time))
    return $selections[./pair[@name = 'time'] = $max_time]/pair[@name='text']/text()
   else ()
:)

let $selected_index := if ($selected_text castable as xs:integer) then xs:integer($selected_text) else -1

let $selected :=
  if ($selected_index = 0)
  then
    /csd:CSD/csd:organizationDirectory/csd:organization[
      @entityID = /csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $top_org/@entityID]/csd:parent/@entityID
    ]
  else if ($selected_index > 0)
  then
    let $select_orgs :=
      if (exists($top_org))
      then /csd:CSD/csd:organizationDirectory/csd:organization[./csd:parent/@entityID = $top_org/@entityID]
      else /csd:CSD/csd:organizationDirectory/csd:organization[count(./csd:parent[@entityID]) = 0]

    let $select_facs :=
      if (exists($top_org))
      then /csd:CSD/csd:facilityDirectory/csd:facility[./csd:organizations/csd:organization[@entityID = $top_org/@entityID]]
      else ()
    return ($select_orgs,$select_facs)[ $selected_index]
  else ()

let $orgs :=
  if (exists($selected) and  local-name($selected ) = 'organization')
  then /csd:CSD/csd:organizationDirectory/csd:organization[./csd:parent/@entityID = $selected/@entityID]
  else /csd:CSD/csd:organizationDirectory/csd:organization[count(./csd:parent[@entityID]) = 0]

let $facs :=
  if (exists($selected) and  local-name($selected ) = 'organization')
  then /csd:CSD/csd:facilityDirectory/csd:facility[./csd:organizations/csd:organization[@entityID = $selected/@entityID]]
  else ()

let $output :=
  if ( local-name($selected ) = 'facility')
  then
    <json type='object'>
      <menutext>You already selected a facility.  You shouldn't see this message</menutext>
      <facility>{string($selected/@entityID)}</facility>
      <facilityname>{$selected/csd:primaryName/text()}</facilityname>
    </json>
  else  if ( local-name($selected ) = 'organization'  or not(exists($selected)))
  then
    <json type='object'>
      <menutext >
 	{ if (exists($selected)) then concat("In ", $selected/csd:primaryName/text(), ". ")  else () }
	{
	  let $parent := (/csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $selected/csd:parent/@entityID])[1]/csd:primaryName/text()
	  return
	    if ($parent)
	    then concat("O) Up to ", $parent, " ")
	    else ()
        }
	{ for $ent at $pos in ($orgs,$facs)  return concat( $pos, ") ", $ent/csd:primaryName/text())    }
      </menutext>
      <orgid>{if (exists($selected)) then string($selected/@entityID) else ()}</orgid>
      <facility/>
      <facilityname/>
    </json>
   else <json type='object'/>

(:return $output :)
return json:serialize($output,map{'format':'direct'})

import module namespace functx = "http://www.functx.com";
declare namespace csd = "urn:ihe:iti:csd:2013";
declare variable $careServicesRequest as item() external;

let $t_top_orgid  :=  $careServicesRequest/query[@name = 'orgid']/text()
let $top_org :=  (/csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $t_top_orgid])[1]

let $selected_text := $careServicesRequest/query[@name = 'input']/text()
(:
let $selections := $careServicesRequest/values/item[./pair[@name = 'label' and ./text() = 'facilityselection']]
let $selected_text :=
  if (count($selections) > 0)
  then
    let $max_time := max(for $time in $selections/pair[@name='time'] return xs:dateTime($time))
    return $selections[./pair[@name = 'time'] = $max_time]/pair[@name='text']/text()
   else ()
:)

let $selected_index := if ($selected_text castable as xs:integer) then xs:integer($selected_text) else -1

let $selected :=
  if ($selected_index = 0)
  then
    /csd:CSD/csd:organizationDirectory/csd:organization[
      @entityID = /csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $top_org/@entityID]/csd:parent/@entityID
    ]
  else if ($selected_index > 0)
  then
    let $select_orgs :=
      if (exists($top_org))
      then /csd:CSD/csd:organizationDirectory/csd:organization[./csd:parent/@entityID = $top_org/@entityID]
      else /csd:CSD/csd:organizationDirectory/csd:organization[count(./csd:parent[@entityID]) = 0]

    let $select_facs :=
      if (exists($top_org))
      then /csd:CSD/csd:facilityDirectory/csd:facility[./csd:organizations/csd:organization[@entityID = $top_org/@entityID]]
      else ()
    return ($select_orgs,$select_facs)[ $selected_index]
  else ()

let $orgs :=
  if (exists($selected) and  local-name($selected ) = 'organization')
  then /csd:CSD/csd:organizationDirectory/csd:organization[./csd:parent/@entityID = $selected/@entityID]
  else /csd:CSD/csd:organizationDirectory/csd:organization[count(./csd:parent[@entityID]) = 0]

let $facs :=
  if (exists($selected) and  local-name($selected ) = 'organization')
  then /csd:CSD/csd:facilityDirectory/csd:facility[./csd:organizations/csd:organization[@entityID = $selected/@entityID]]
  else ()

let $output :=
  if ( local-name($selected ) = 'facility')
  then
    <json type='object'>
      <menutext>You already selected a facility.  You shouldn't see this message</menutext>
      <facility>{string($selected/@entityID)}</facility>
      <facilityname>{$selected/csd:primaryName/text()}</facilityname>
    </json>
  else  if ( local-name($selected ) = 'organization'  or not(exists($selected)))
  then
    <json type='object'>
      <menutext >
 	{ if (exists($selected)) then concat("In ", $selected/csd:primaryName/text(), ". ")  else () }
	{
	  let $parent := (/csd:CSD/csd:organizationDirectory/csd:organization[@entityID = $selected/csd:parent/@entityID])[1]/csd:primaryName/text()
	  return
	    if ($parent)
	    then concat("O) Up to ", $parent, " ")
	    else ()
        }
	{ for $ent at $pos in ($orgs,$facs)  return concat( $pos, ") ", $ent/csd:primaryName/text())    }
      </menutext>
      <orgid>{if (exists($selected)) then string($selected/@entityID) else ()}</orgid>
      <facility/>
      <facilityname/>
      <selectedname>{if (exists($selected)) then $selected/csd:primaryName/text() else () }</selectedname>
      <selectedID>{if (exists($selected)) then string($selected/@entityID) else () }</selectedID>
      <selectedtext>{$selected_text}</selectedtext>
      <selectedindex>{$selected_index}</selectedindex>
    </json>
   else <json type='object'/>

(:return $output :)
return json:serialize($output,map{'format':'direct'})


[FIX] No grouping of regex variable. Closes #1521

(:~
 : Main page.
 :
 : @author Christian Grün, BaseX Team, 2014-17
 :)
module namespace dba = 'dba/databases';

import module namespace cons = 'dba/cons' at '../modules/cons.xqm';
import module namespace html = 'dba/html' at '../modules/html.xqm';
import module namespace util = 'dba/util' at '../modules/util.xqm';

(:~ Top category :)
declare variable $dba:CAT := 'databases';

(:~ Regular expression for backups. :)
declare variable $dba:BACKUP-REGEX := '^(.*)-(\d{4}-\d\d-\d\d)-(\d\d)-(\d\d)-(\d\d)$';

(:~
 : Main page.
 : @param  $sort   table sort key
 : @param  $error  error string
 : @param  $info   info string
 : @param  $page   current page
 : @return page
 :)
declare
  %rest:GET
  %rest:path("/dba/databases")
  %rest:query-param("sort",  "{$sort}", "")
  %rest:query-param("page",  "{$page}", 1)
  %rest:query-param("info",  "{$info}")
  %rest:query-param("error", "{$error}")
  %output:method("html")
function dba:databases(
  $sort   as xs:string,
  $page   as xs:integer,
  $info   as xs:string?,
  $error  as xs:string?
) as element(html) {
  cons:check(),

  let $names := map:merge(db:list() ! map:entry(., true()))
  let $databases :=
    let $start := util:start($page, $sort)
    let $end := util:end($page, $sort)
    for $db in db:list-details()[position() = $start to $end]
    return <row name='{ $db }' resources='{ $db/@resources }' size='{ $db/@size }'
                date='{ $db/@modified-date }'/>
  let $backups :=
    for $backup in db:backups()
    where matches($backup, $dba:BACKUP-REGEX)
    group by $name := replace($backup, $dba:BACKUP-REGEX, '$1')
    where not($names($name))
    let $date := replace(sort($backup)[last()], $dba:BACKUP-REGEX, '$2T$3:$4:$5Z')
    return <row name='{ $name }' resources='' size='(backup)' date='{ $date }'/>

  return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },

        <form action="{ $dba:CAT }" method="post" class="update">

Databases

          {
            let $headers := (
              <name>Name</name>,
              <resources type='number' order='desc'>Count</resources>,
              <size type='bytes' order='desc'>Bytes</size>,
              <date type='dateTime' order='desc'>Last Modified</date>
            )
            let $rows := ($databases, $backups)
            let $buttons := (
              html:button('db-create', 'Create…'),
              html:button('db-optimize-all', 'Optimize'),
              html:button('db-drop', 'Drop', true())
            )
            let $link := function($value) { 'database' }
            let $count := map:size($names) + count($backups)
            return html:table($headers, $rows, $buttons, map { },
              map { 'sort': $sort, 'link': $link, 'page': $page, 'count': $count })
          }
        </form>

  )
};

(:~
 : Redirects to the specified action.
 : @param  $action  action to perform
 : @param  $names   names of selected databases
 : @return redirection
 :)
declare
  %rest:POST
  %rest:path("/dba/databases")
  %rest:query-param("action", "{$action}")
  %rest:query-param("name",   "{$names}")
function dba:databases-redirect(
  $action  as xs:string,
  $names   as xs:string*
) as element(rest:response) {
  web:redirect($action,
    if($action = 'create-db') then map { }
    else map { 'name': $names, 'redirect': $dba:CAT }
  )
};

(:~
 : Main page.
 :
 : @author Christian Grün, BaseX Team, 2014-17
 :)
module namespace dba = 'dba/databases';

import module namespace cons = 'dba/cons' at '../modules/cons.xqm';
import module namespace html = 'dba/html' at '../modules/html.xqm';
import module namespace util = 'dba/util' at '../modules/util.xqm';

(:~ Top category :)
declare variable $dba:CAT := 'databases';

(:~
 : Main page.
 : @param  $sort   table sort key
 : @param  $error  error string
 : @param  $info   info string
 : @param  $page   current page
 : @return page
 :)
declare
  %rest:GET
  %rest:path("/dba/databases")
  %rest:query-param("sort",  "{$sort}", "")
  %rest:query-param("page",  "{$page}", 1)
  %rest:query-param("info",  "{$info}")
  %rest:query-param("error", "{$error}")
  %output:method("html")
function dba:databases(
  $sort   as xs:string,
  $page   as xs:integer,
  $info   as xs:string?,
  $error  as xs:string?
) as element(html) {
  cons:check(),

  let $names := map:merge(db:list() ! map:entry(., true()))
  let $databases :=
    let $start := util:start($page, $sort)
    let $end := util:end($page, $sort)
    for $db in db:list-details()[position() = $start to $end]
    return <row name='{ $db }' resources='{ $db/@resources }' size='{ $db/@size }'
                date='{ $db/@modified-date }'/>
  let $backups :=
    let $regex := '^(.*)-(\d{4}-\d\d-\d\d)-(\d\d)-(\d\d)-(\d\d)$'
    for $backup in db:backups()
    where matches($backup, $regex)
    group by $name := replace($backup, $regex, '$1')
    where not($names($name))
    let $date := replace(sort($backup)[last()], $regex, '$2T$3:$4:$5Z')
    return <row name='{ $name }' resources='' size='(backup)' date='{ $date }'/>

  return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },

        <form action="{ $dba:CAT }" method="post" class="update">

Databases

          {
            let $headers := (
              <name>Name</name>,
              <resources type='number' order='desc'>Count</resources>,
              <size type='bytes' order='desc'>Bytes</size>,
              <date type='dateTime' order='desc'>Last Modified</date>
            )
            let $rows := ($databases, $backups)
            let $buttons := (
              html:button('db-create', 'Create…'),
              html:button('db-optimize-all', 'Optimize'),
              html:button('db-drop', 'Drop', true())
            )
            let $link := function($value) { 'database' }
            let $count := map:size($names) + count($backups)
            return html:table($headers, $rows, $buttons, map { },
              map { 'sort': $sort, 'link': $link, 'page': $page, 'count': $count })
          }
        </form>

  )
};

(:~
 : Redirects to the specified action.
 : @param  $action  action to perform
 : @param  $names   names of selected databases
 : @return redirection
 :)
declare
  %rest:POST
  %rest:path("/dba/databases")
  %rest:query-param("action", "{$action}")
  %rest:query-param("name",   "{$names}")
function dba:databases-redirect(
  $action  as xs:string,
  $names   as xs:string*
) as element(rest:response) {
  web:redirect($action,
    if($action = 'create-db') then map { }
    else map { 'name': $names, 'redirect': $dba:CAT }
  )
};


pass config:mappings-file as param to xsl

module namespace repo-utils = "http://aac.ac.at/content_repository/utils";

import module namespace xdb="http://exist-db.org/xquery/xmldb";
import module namespace diag =  "http://www.loc.gov/zing/srw/diagnostic/" at  "modules/diagnostics/diagnostics.xqm";

(:~ HELPER functions - configuration, caching, data-access
:)

(:
: this all cannot be defined as global variable, because we want different configurations,
: thus the $config has to be sent as param everywhere
: declare variable $repo-utils:config := doc("config.xml");
: declare variable $repo-utils:mappings := doc(repo-utils:config-value('mappings'));
: declare variable $repo-utils:data-collection := collection(repo-utils:config-value('data.path'));
: declare variable $repo-utils:md-collection := collection(repo-utils:config-value('metadata.path'));
: declare variable $repo-utils:cachePath as xs:string := repo-utils:config-value('cache.path');
:)

declare variable $repo-utils:xmlExt as xs:string := ".xml";
declare variable $repo-utils:responseFormatXml as xs:string := "xml";
declare variable $repo-utils:responseFormatJSon as xs:string := "json";
declare variable $repo-utils:responseFormatText as xs:string := "text";
declare variable $repo-utils:responseFormatHTML as xs:string := "html";

declare function repo-utils:config-value($config, $key as xs:string) as xs:string* {
    $config//property[@key=$key]
};

(:~ Get value of a param based on a key, from config or from request-param (precedence) :)
declare function repo-utils:param-value($config, $key as xs:string, $default as xs:string) as xs:string* {

    let $param := request:get-parameter($key, $default)
    return if ($param) then $param else $config//property[@key=$key]
};

(:~ returns db-collection (as nodeset) based on the identifier in x-context, looked up in the mapping or default collection as defined in config

@returns nodeset of given context
 if no x-context match or no context provided returns default collection from the config (data.path )
 (if available, otherwise again empty result)

WATCHME: changed to lax handling of the context (if no match - go to default)
        gives better recall, but may confuse - alternatively: strict: empty result if x-context does not match
TODO: accept $x-context as xs:string*
:)
declare function repo-utils:context-to-collection($x-context as xs:string, $config) as node()* {
(:      let $mappings := doc(repo-utils:config-value($config, 'mappings')):)
      let $dbcoll-path := repo-utils:context-to-collection-path($x-context, $config)
    return if ($dbcoll-path eq "" ) then ()
                else collection($dbcoll-path)
};

(:~ returns path to db-collection (as nodeset) based on the identifier in x-context,
looked up in the mapping or default data.path as defined in config

@returns dbcoll-path of given context
 if no x-context match or no context provided returns default collection from the config (data.path )
 (if available, otherwise again empty result)

WATCHME: changed to lax handling of the context (if no match - go to default)
        gives better recall, but may confuse - alternatively: strict: empty result if x-context does not match
T
:)
declare function repo-utils:context-to-collection-path($x-context as xs:string, $config) as xs:string {
      let $mappings:= doc(repo-utils:config-value($config, 'mappings'))
    return    (: if ($x-context) then :)
            if (exists($mappings//map[xs:string(@key) eq $x-context]/@path)) then
                    $mappings//map[xs:string(@key) eq $x-context]/xs:string(@path)
                (: else "" :)
                  else if (exists(repo-utils:config-value($config, 'data.path'))) then
                        repo-utils:config-value($config, 'data.path')
                  else ""
};

(:~ Get the resource by PID/handle/URL or some known identifier.
  TODO: NOT ADAPTED YET! (taken from CMD)
  TODO: be clear about resource itself and metadata-record!
:)
(:declare function repo-utils:get-resource-by-id($id as xs:string) as node()* {
  let $collection := collection($cr:dataPath)
  return
    if ($id eq "" or $id eq $cr:collectionRoot) then
    $collection//IsPartOf[. = $cr:collectionRoot]/ancestor::CMD
  else
    util:eval(concat("$collection/ft:query(descendant::MdSelfLink, <term>", xdb:decode($id), "</term>)/ancestor::CMD"))
 (\: $collection/descendant::MdSelfLink[. = xdb:decode($id)]/ancestor::CMD :\)
};
:)

(:~ Checks whether the document is available or not.
  generic, currently not used
:)
declare function repo-utils:is-doc-available($collection as xs:string, $doc-name as xs:string) as xs:boolean {
  fn:doc-available(fn:concat($collection, "/", $doc-name))
};

declare function repo-utils:is-in-cache($doc-name as xs:string,$config) as xs:boolean {
  fn:doc-available(fn:concat(repo-utils:config-value($config, 'cache.path'), "/", $doc-name))
};

declare function repo-utils:get-from-cache($doc-name as xs:string,$config) as item()* {
      fn:doc(fn:concat(repo-utils:config-value($config, 'cache.path'), "/", $doc-name))
};

(:~ Store the data in cache. Uses own writer-account
:)
declare function repo-utils:store-in-cache($doc-name as xs:string, $data as node(),$config) as item()* {
  let $clarin-writer := fn:doc("/db/cr/writer.xml"),
  $cache-path := repo-utils:config-value($config, 'cache.path'),
  $dummy := xdb:login($cache-path, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text()),
  $store := (: util:catch("org.exist.xquery.XPathException", :) xdb:store($cache-path, $doc-name, $data), (: , ()) :)
  $stored-doc := fn:doc(concat($cache-path, "/", $doc-name))
  return $stored-doc
(:  ():)
};

(:
this tries to create sub-collections in index for
individual data-collection - but it makes the retrieval etc. also more complicated
so rather encoding the data-collection also in the name

declare function repo-utils:store-in-cache($data-collection as item(), $doc-name as xs:string, $data as node()) as item()* {
    let $data-coll-name := collection-name($data-collection)
    let $index-coll-path := concat($repo-utils:cachePath, "/", $data-coll-name )
   let $create-coll := if (not(xmldb:collection-available($index-coll-path ))) then
                           xmldb:create-collection($repo-utils:cachePath, $data-collname) else ()
  let $store-result := repo-utils:store($index-coll-path, $doc-name, $data, true())

return $store-result
};
:)

(:<options><option key="update">yes</option></options>:)
declare function repo-utils:store($collection as xs:string, $doc-name as xs:string, $data as node(), $overwrite as xs:boolean) as item()* {
  let $clarin-writer := fn:doc("/db/cr/writer.xml"),
  $dummy := xdb:login($collection, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text())

  let $rem := if ($overwrite and doc-available(concat($collection, $doc-name))) then xdb:remove($collection, $doc-name) else ()

  let $store := (: util:catch("org.exist.xquery.XPathException", :) xdb:store($collection, $doc-name, $data), (: , ()) :)
  $stored-doc := fn:doc(concat($collection, "/", $doc-name))
  return $stored-doc
};

(:~ Create document name with md5-hash for selected collections (or types) for reuse.
:)
declare function repo-utils:gen-cache-id($type-name as xs:string, $keys as xs:string+, $depth as xs:string) as xs:string {
  let $name-prefix := fn:concat($type-name, $depth),
       $sanitized-names := for $key in $keys return repo-utils:sanitize-name($key)
    return
(:    fn:concat($name-prefix, "-", util:hash(string-join($sorted-names, ""), "MD5"), $repo-utils:xmlExt):)
    fn:concat($name-prefix, "-", string-join($sanitized-names, "-"), $repo-utils:xmlExt)
};

(:~ wipes out problematic characters from names
:)
declare function repo-utils:sanitize-name($name as xs:string) as xs:string {
    translate($name, ":",'_')
};

declare function repo-utils:serialise-as($item as node()?, $format as xs:string, $operation as xs:string, $config) as item()? {
    repo-utils:serialise-as($item, $format, $operation, $config, ())
};

(:~ transform result to HTML, JSON, or leave as XML - according to format parameter

@param $parameters optional additional parameters to be passed to xsl
:)
declare function repo-utils:serialise-as($item as node()?, $format as xs:string, $operation as xs:string, $config, $parameters as node()* ) as item()? {
      if ($format eq $repo-utils:responseFormatJSon) then
	       let $option := util:declare-option("exist:serialize", "method=json media-type=application/json")
	       return $item
	    else if (contains($format, $repo-utils:responseFormatHTML)) then
	           let $xslDoc := doc(concat(repo-utils:config-value($config, 'scripts.path'), repo-utils:config-value($config, concat($operation, ".xsl"))) )
	           let $res := transform:transform($item,$xslDoc,
              			<parameters><param name="format" value="{$format}"/>
              			            <param name="x-context" value="{repo-utils:param-value($config, 'x-context', '' )}"/>
              			            <param name="base_url" value="{repo-utils:config-value($config, 'base.url')}"/>
              			            <param name="mappings-file" value="{repo-utils:config-value($config, 'mappings')}"/>
              			            <param name="scripts_url" value="{repo-utils:config-value($config, 'scripts.url')}"/>
              			             <param name="site_name" value="{repo-utils:config-value($config, 'site.name')}"/>
              			             {$parameters/param}
              			</parameters>)
(:               let $option := util:declare-option("exist:serialize", "method=xml media-type=text/html"):)
let $option := util:declare-option("exist:serialize", "method=xhtml media-type=text/html")
	           return $res
	   else
	       let $option := util:declare-option("exist:serialize", "method=xml media-type=application/xml")
	    return $item
};
(: $repo-utils:responseFormatXml, $repo-utils:responseFormatText:)

	    (:let $option :=
	              if (contains($format, $repo-utils:responseFormatHTML)) then
	                  util:declare-option("exist:serialize", "method=xml media-type=text/xhtml")
	              else
    	              util:declare-option("exist:serialize", "method=xml media-type=application/xml")
:)

	          	(: $item :)

module namespace repo-utils = "http://aac.ac.at/content_repository/utils";

import module namespace xdb="http://exist-db.org/xquery/xmldb";
import module namespace diag =  "http://www.loc.gov/zing/srw/diagnostic/" at  "modules/diagnostics/diagnostics.xqm";

(:~ HELPER functions - configuration, caching, data-access
:)

(:
: this all cannot be defined as global variable, because we want different configurations,
: thus the $config has to be sent as param everywhere
: declare variable $repo-utils:config := doc("config.xml");
: declare variable $repo-utils:mappings := doc(repo-utils:config-value('mappings'));
: declare variable $repo-utils:data-collection := collection(repo-utils:config-value('data.path'));
: declare variable $repo-utils:md-collection := collection(repo-utils:config-value('metadata.path'));
: declare variable $repo-utils:cachePath as xs:string := repo-utils:config-value('cache.path');
:)

declare variable $repo-utils:xmlExt as xs:string := ".xml";
declare variable $repo-utils:responseFormatXml as xs:string := "xml";
declare variable $repo-utils:responseFormatJSon as xs:string := "json";
declare variable $repo-utils:responseFormatText as xs:string := "text";
declare variable $repo-utils:responseFormatHTML as xs:string := "html";

declare function repo-utils:config-value($config, $key as xs:string) as xs:string* {
    $config//property[@key=$key]
};

(:~ Get value of a param based on a key, from config or from request-param (precedence) :)
declare function repo-utils:param-value($config, $key as xs:string, $default as xs:string) as xs:string* {

    let $param := request:get-parameter($key, $default)
    return if ($param) then $param else $config//property[@key=$key]
};

(:~ returns db-collection (as nodeset) based on the identifier in x-context, looked up in the mapping or default collection as defined in config

@returns nodeset of given context
 if no x-context match or no context provided returns default collection from the config (data.path )
 (if available, otherwise again empty result)

WATCHME: changed to lax handling of the context (if no match - go to default)
        gives better recall, but may confuse - alternatively: strict: empty result if x-context does not match
TODO: accept $x-context as xs:string*
:)
declare function repo-utils:context-to-collection($x-context as xs:string, $config) as node()* {
(:      let $mappings := doc(repo-utils:config-value($config, 'mappings')):)
      let $dbcoll-path := repo-utils:context-to-collection-path($x-context, $config)
    return if ($dbcoll-path eq "" ) then ()
                else collection($dbcoll-path)
};

(:~ returns path to db-collection (as nodeset) based on the identifier in x-context,
looked up in the mapping or default data.path as defined in config

@returns dbcoll-path of given context
 if no x-context match or no context provided returns default collection from the config (data.path )
 (if available, otherwise again empty result)

WATCHME: changed to lax handling of the context (if no match - go to default)
        gives better recall, but may confuse - alternatively: strict: empty result if x-context does not match
T
:)
declare function repo-utils:context-to-collection-path($x-context as xs:string, $config) as xs:string {
      let $mappings:= doc(repo-utils:config-value($config, 'mappings'))
    return    (: if ($x-context) then :)
            if (exists($mappings//map[xs:string(@key) eq $x-context]/@path)) then
                    $mappings//map[xs:string(@key) eq $x-context]/xs:string(@path)
                (: else "" :)
                  else if (exists(repo-utils:config-value($config, 'data.path'))) then
                        repo-utils:config-value($config, 'data.path')
                  else ""
};

(:~ Get the resource by PID/handle/URL or some known identifier.
  TODO: NOT ADAPTED YET! (taken from CMD)
  TODO: be clear about resource itself and metadata-record!
:)
(:declare function repo-utils:get-resource-by-id($id as xs:string) as node()* {
  let $collection := collection($cr:dataPath)
  return
    if ($id eq "" or $id eq $cr:collectionRoot) then
    $collection//IsPartOf[. = $cr:collectionRoot]/ancestor::CMD
  else
    util:eval(concat("$collection/ft:query(descendant::MdSelfLink, <term>", xdb:decode($id), "</term>)/ancestor::CMD"))
 (\: $collection/descendant::MdSelfLink[. = xdb:decode($id)]/ancestor::CMD :\)
};
:)

(:~ Checks whether the document is available or not.
  generic, currently not used
:)
declare function repo-utils:is-doc-available($collection as xs:string, $doc-name as xs:string) as xs:boolean {
  fn:doc-available(fn:concat($collection, "/", $doc-name))
};

declare function repo-utils:is-in-cache($doc-name as xs:string,$config) as xs:boolean {
  fn:doc-available(fn:concat(repo-utils:config-value($config, 'cache.path'), "/", $doc-name))
};

declare function repo-utils:get-from-cache($doc-name as xs:string,$config) as item()* {
      fn:doc(fn:concat(repo-utils:config-value($config, 'cache.path'), "/", $doc-name))
};

(:~ Store the data in cache. Uses own writer-account
:)
declare function repo-utils:store-in-cache($doc-name as xs:string, $data as node(),$config) as item()* {
  let $clarin-writer := fn:doc("/db/cr/writer.xml"),
  $cache-path := repo-utils:config-value($config, 'cache.path'),
  $dummy := xdb:login($cache-path, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text()),
  $store := (: util:catch("org.exist.xquery.XPathException", :) xdb:store($cache-path, $doc-name, $data), (: , ()) :)
  $stored-doc := fn:doc(concat($cache-path, "/", $doc-name))
  return $stored-doc
(:  ():)
};

(:
this tries to create sub-collections in index for
individual data-collection - but it makes the retrieval etc. also more complicated
so rather encoding the data-collection also in the name

declare function repo-utils:store-in-cache($data-collection as item(), $doc-name as xs:string, $data as node()) as item()* {
    let $data-coll-name := collection-name($data-collection)
    let $index-coll-path := concat($repo-utils:cachePath, "/", $data-coll-name )
   let $create-coll := if (not(xmldb:collection-available($index-coll-path ))) then
                           xmldb:create-collection($repo-utils:cachePath, $data-collname) else ()
  let $store-result := repo-utils:store($index-coll-path, $doc-name, $data, true())

return $store-result
};
:)

(:<options><option key="update">yes</option></options>:)
declare function repo-utils:store($collection as xs:string, $doc-name as xs:string, $data as node(), $overwrite as xs:boolean) as item()* {
  let $clarin-writer := fn:doc("/db/cr/writer.xml"),
  $dummy := xdb:login($collection, $clarin-writer//write-user/text(), $clarin-writer//write-user-cred/text())

  let $rem := if ($overwrite and doc-available(concat($collection, $doc-name))) then xdb:remove($collection, $doc-name) else ()

  let $store := (: util:catch("org.exist.xquery.XPathException", :) xdb:store($collection, $doc-name, $data), (: , ()) :)
  $stored-doc := fn:doc(concat($collection, "/", $doc-name))
  return $stored-doc
};

(:~ Create document name with md5-hash for selected collections (or types) for reuse.
:)
declare function repo-utils:gen-cache-id($type-name as xs:string, $keys as xs:string+, $depth as xs:string) as xs:string {
  let $name-prefix := fn:concat($type-name, $depth),
       $sanitized-names := for $key in $keys return repo-utils:sanitize-name($key)
    return
(:    fn:concat($name-prefix, "-", util:hash(string-join($sorted-names, ""), "MD5"), $repo-utils:xmlExt):)
    fn:concat($name-prefix, "-", string-join($sanitized-names, "-"), $repo-utils:xmlExt)
};

(:~ wipes out problematic characters from names
:)
declare function repo-utils:sanitize-name($name as xs:string) as xs:string {
    translate($name, ":",'_')
};

declare function repo-utils:serialise-as($item as node()?, $format as xs:string, $operation as xs:string, $config) as item()? {
    repo-utils:serialise-as($item, $format, $operation, $config, ())
};

(:~ transform result to HTML, JSON, or leave as XML - according to format parameter

@param $parameters optional additional parameters to be passed to xsl
:)
declare function repo-utils:serialise-as($item as node()?, $format as xs:string, $operation as xs:string, $config, $parameters as node()* ) as item()? {
      if ($format eq $repo-utils:responseFormatJSon) then
	       let $option := util:declare-option("exist:serialize", "method=json media-type=application/json")
	       return $item
	    else if (contains($format, $repo-utils:responseFormatHTML)) then
	           let $xslDoc := doc(concat(repo-utils:config-value($config, 'scripts.path'), repo-utils:config-value($config, concat($operation, ".xsl"))) )
	           let $res := transform:transform($item,$xslDoc,
              			<parameters><param name="format" value="{$format}"/>
              			            <param name="x-context" value="{repo-utils:param-value($config, 'x-context', '' )}"/>
              			            <param name="base_url" value="{repo-utils:config-value($config, 'base.url')}"/>
              			            <param name="scripts_url" value="{repo-utils:config-value($config, 'scripts.url')}"/>
              			             <param name="site_name" value="{repo-utils:config-value($config, 'site.name')}"/>
              			             {$parameters/param}
              			</parameters>)
(:               let $option := util:declare-option("exist:serialize", "method=xml media-type=text/html"):)
let $option := util:declare-option("exist:serialize", "method=xhtml media-type=text/html")
	           return $res
	   else
	       let $option := util:declare-option("exist:serialize", "method=xml media-type=application/xml")
	    return $item
};
(: $repo-utils:responseFormatXml, $repo-utils:responseFormatText:)

	    (:let $option :=
	              if (contains($format, $repo-utils:responseFormatHTML)) then
	                  util:declare-option("exist:serialize", "method=xml media-type=text/xhtml")
	              else
    	              util:declare-option("exist:serialize", "method=xml media-type=application/xml")
:)

	          	(: $item :)