declare namespace svg ="http://www.w3.org/2000/svg"; let $rects := //svg:rect let $texts := //svg:text let $labels := for $text in $texts where matches($text/@id , "^label.*") return concat ( $text/@x, " ", $text/@y, " ", replace($text/@style, ".*fill:#([0-9a-z]{6}).*", "$1"), " ", (: TODO: svg2rects doesn't handle newlines in labels :) string-join($text/svg:tspan/text(), " ") ) let $player := for $rect in $rects where $rect/@id = "player" return concat ( $rect/@x, " ", $rect/@y, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) let $platforms := for $rect in $rects where matches($rect/@id, "^rect.*") return concat ( $rect/@x, " ", $rect/@y, " ", $rect/@width, " ", $rect/@height, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) let $boxes := for $rect in $rects where matches($rect/@id, "^box.*") return concat ( $rect/@id, " ", $rect/@x, " ", $rect/@y, " ", $rect/@width, " ", $rect/@height, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) let $regions := for $rect in $rects where matches($rect/@id, "region.*") return $rect let $goals := for $rect in $rects where matches($rect/@id, "goal.*") return ( let $goal_id := replace($rect/@id, "goal(.*)", "$1") let $goal_region := for $region in $regions where $region/@id = concat("region", $goal_id) return $region return concat ( $rect/@x, " ", $rect/@y, " ", $goal_region[1]/@x, " ", $goal_region[1]/@y, " ", $goal_region[1]/@width, " ", $goal_region[1]/@height, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) ) let $lavas := for $rect in $rects where matches($rect/@id, "lava.*") return concat ( $rect/@x, " ", $rect/@y, " ", $rect/@width, " ", $rect/@height, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) let $background := for $rect in $rects where $rect/@id = "background" return replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") let $backplatforms := for $rect in $rects where matches($rect/@id, "^backrect.*") return concat ( $rect/@x, " ", $rect/@y, " ", $rect/@width, " ", $rect/@height, " ", replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1") ) return ( $background, $player, count($platforms), $platforms, count($goals), $goals, count($lavas), $lavas, count($backplatforms), $backplatforms, count($boxes), $boxes, count($labels), $labels )