As you are using BaseX, please visit this link -
http://docs.basex.org/wiki/File_Module#file:append
for $x in doc('DBNAME')//Doc
where $x/@year eq '2010'
return file:append("C:\2010.xml", $x)
This query will extract the required data in file named 2010.xml in C drive. File name and location can be changed as per you requirement.
Using above query you will have change the year value 2010
as required. If you have year with different values and in order, as I see from the structure, you can use following query. This query will create multiple files, for all the years.
for $year in (2010 to 2011)
(: Year are specified :)
let $fName := concat("C:\", $year, "B.xml")
(: The path is created and stored in $fName variable :)
for $x in doc('docs')//Doc
where $x/@year eq xs:string($year)
return file:append($fName, $x)
I hope both the examples are quite self explanatory.