(: file: create_initial_xwalk_var1_to_var2.xq date: 31-August-2010 author: Gary Lewis purpose: Creates an initial crosswalk from the codes in one specified variable to the corresponding codes in a second specified variable. Uses the code labels to determine the crosswalk. The output file can then be edited manually to adjust the crosswalk. This is particularly helpful when the variables in question have a large number of codes. notes: 1. $varYear is the year used to determine the datatype of variable $var (for sorting purposes). 2. All distinct values of $var codes for years <= $varYear are included in the crosswalk. 3. The value label $varLabel associated with $var is the one occurring in the most recent survey year where a value for $var exists. 4. The crosswalk from $var to $toVar is determined by matching $varLabel in the specified year $toVarYear. usage: Run from the location where the program is located. example: zorba -e var:="geost" -e varYear:="1985" -e toVar:="fips" -e toVarYear:="2008" -f -q create_initial_xwalk_var1_to_var2.xq -o initial_xwalk_geost_to_fips.xml -z indent=yes :) declare variable $var external; declare variable $varYear external; declare variable $toVar external; declare variable $toVarYear external; { let $datatype := doc("../xml/metadata/ipedsVars_metadata.xml")/variables/var[@name = $var]/detail[@year = $varYear]/@dataType, $i := doc("../xml/metadata/ipedsVars_metadata_codes.xml")/variables/var[@name = $var][@year <= $varYear], $j := doc("../xml/metadata/ipedsVars_metadata_codes.xml")/variables/var[@name = $toVar][@year = $toVarYear] for $varValue in distinct-values($i/code/@value) let $labelYear := max($i/code[@value = $varValue]/../@year), $varLabel := $i[@year = $labelYear]/code[@value = $varValue]/@label, $toVarValue := $j/code[@label = $varLabel]/@value order by (if ($datatype eq "N") then xs:integer($varValue) else $varValue) return }