<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:marc="http://www.loc.gov/MARC21/slim">

	<xsl:variable name="school" select="doc('atlanta_schools_markup.xml')"/>

	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="marc:record" name="selected">


		<xsl:variable name="schCODE">
			<xsl:for-each select="marc:datafield[@tag='949']/marc:subfield[@code='a']">
				<xsl:value-of select="substring(., 1, 4)"/>
			</xsl:for-each>
		</xsl:variable>

		<xsl:if test="$schCODE = $school/*/code">
			<xsl:variable name="file">
				<xsl:for-each select="$school/*/code">
					<xsl:if test=". = $schCODE">
						<xsl:value-of select="concat(./following-sibling::name, '.xml')"/>
					</xsl:if>
				</xsl:for-each>
			</xsl:variable>

			<xsl:result-document href="{$file}">
				<xsl:copy>
					<xsl:apply-templates select="@*,node()"/>
				</xsl:copy>
			</xsl:result-document>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2009. Progress Software Corporation. All rights reserved.

<metaInformation>
	<scenarios>
		<scenario default="yes" name="Extract school records from district collection" userelativepaths="yes" externalpreview="no" url="..\..\Atlanta_Records\processed_files\msplit00000000.xml" htmlbaseurl="" outputurl="" processortype="saxon8"
		          useresolver="yes" profilemode="6" profiledepth="" profilelength="" urlprofilexml="file:///c:/Users/DBP/Documents/Documents/dbp_metadataXMLservices/WORKSHOP/Renaissance/MISC/javaProblem.xml" commandline="" additionalpath=""
		          additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="">
			<advancedProp name="sInitialMode" value=""/>
			<advancedProp name="bXsltOneIsOkay" value="true"/>
			<advancedProp name="bSchemaAware" value="true"/>
			<advancedProp name="bXml11" value="false"/>
			<advancedProp name="iValidation" value="0"/>
			<advancedProp name="bExtensions" value="true"/>
			<advancedProp name="iWhitespace" value="0"/>
			<advancedProp name="sInitialTemplate" value=""/>
			<advancedProp name="bTinyTree" value="true"/>
			<advancedProp name="bWarnings" value="true"/>
			<advancedProp name="bUseDTD" value="false"/>
			<advancedProp name="iErrorHandling" value="0"/>
		</scenario>
	</scenarios>
	<MapperMetaTag>
		<MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no">
			<SourceSchema srcSchemaPath="..\..\..\DCLstylesheet\Tyndel_catalog.xml" srcSchemaRoot="ONIXMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/>
		</MapperInfo>
		<MapperBlockPosition>
			<template match="ONIXMessage"></template>
			<template match="Product"></template>
		</MapperBlockPosition>
		<TemplateContext></TemplateContext>
		<MapperFilter side="source"></MapperFilter>
	</MapperMetaTag>
</metaInformation>
-->