declare namespace eg ='http://example.com#'; declare namespace its ='http://www.w3.org/2005/11/its'; declare function eg:writePath($node as item()*,$path as xs:string) as xs:string { if ($node[self::element() or self::attribute()]) then (let $position := count($node/preceding-sibling::*[name() = name($node)]) +1 let $newpath := if ($node[self::element()]) then( concat(name($node), '[', $position,']/', $path)) else( concat($path, '@', name($node), '/')) return eg:writePath($node/parent::*,$newpath)) else substring((concat('/',$path)),0,string-length($path)+1) }; declare function eg:testNodeTranslate($nodes as item()*) as item()* { if(empty($nodes)) then() else ( element eg:node { if($nodes[1]/@its:translate) then ( attribute eg:translateValue { concat ($nodes[1]/@its:translate, ' (contigent)') }, attribute eg:translateSelector {eg:writePath($nodes[1],'')} ) else if($nodes[1]/ancestor::*[@its:translate] and $nodes[1]/self::element()) then ( attribute eg:translateValue { concat( $nodes[1]/ancestor::*[@its:translate][1]/@its:translate,' (inherited)') }, attribute eg:translateSelector {eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')//bibref) then ( attribute eg:translateValue {'no (autonomous)'}, attribute eg:translateSelector { eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')//@*) then (attribute eg:translateValue {'no (default)'}, attribute eg:translateSelector { eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')/descendant-or-self::*) then (attribute eg:translateValue {'yes (default)'}, attribute eg:translateSelector { eg:writePath($nodes[1],'')} ) else() } , eg:testNodeTranslate($nodes[position()>1])) }; declare function eg:testNodeDir($nodes as item()*) as item()* { if(empty($nodes)) then() else ( element eg:node { if($nodes[1]/@its:dir) then ( attribute eg:dirValue { concat ($nodes[1]/@its:dir, ' (contigent)') }, attribute eg:dirSelector {eg:writePath($nodes[1],'')} ) else if($nodes[1]/ancestor::*[@its:dir]) then ( attribute eg:dirValue { concat( $nodes[1]/ancestor::*[@its:dir][1]/@its:dir, ' (inherited)' )}, attribute eg:dirSelector {eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')) then ( attribute eg:dirValue {' (autonomous)'}, attribute eg:dirSelector { eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')//@*) then (attribute eg:dirValue {'ltr (default)'}, attribute eg:dirSelector { eg:writePath($nodes[1],'')} ) else if ($nodes[1] intersect doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')/descendant-or-self::*) then (attribute eg:dirValue {'ltr (default)'}, attribute eg:dirSelector { eg:writePath($nodes[1],'')} ) else() } , eg:testNodeDir($nodes[position()>1])) }; let$inputDoc := (doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')//*[not(namespace-uri()='http://www.w3.org/2005/11/its')] | doc('file:/c:/users/felix/www/International/its/tests/xmlspec2-input.xml')//@*[not(namespace-uri()='http://www.w3.org/2005/11/its') and not(namespace-uri()='http://www.w3.org/XML/1998/namespace')]) return element eg:selections { element eg:TranslateSelections { eg:testNodeTranslate($inputDoc) }, element eg:dirSelections { eg:testNodeDir($inputDoc) } }