This question is directly related to Aligning TikZ trees with other nodes that I asked some time ago. By the time I asked the question I didn't realize that aligning multiple trees was not the same as aligning one tree. Indeed, the answer proposed by Dmitry F. Volosnykh demands that the tree is created first, before the other nodes it has to be aligned with. Thus, that question should have been named "Aligning one TikZ tree with other nodes".
However, when you have to align multiple trees, they can't be in first position all together at the same time. Some have to appear after others.
I have completed the example given in the previous question to be the full example I need to solve and to expose the problem I am talking about. Note that the three fitting nodes used to contain the three trees are at the right positions. But all the trees are at the same coordinates and are superimposed on the "transformation" box.
Here is the graphic I get:
Of course, I would like to be able to position them in their respective box.
Here is the code:
\documentclass{article}
\usepackage{tikz,nicefrac,amsmath,pifont,graphicx}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,positioning,trees}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}
\graphicspath{{/Users/ludo/Documents/cours/xml/slides/gfx/}{/Users/ludo/Documents/cours/xml/slides/src/gfx/}}
\begin{document}
\begin{tikzpicture}[
>=stealth', semithick, node distance=1cm, level distance=7mm, level/.style={sibling distance=10mm/#1},
block/.style = {draw, rectangle, rounded corners, minimum height=1cm},
every node/.style={circle, draw, fill=none, anchor=north}
]
\node [block] (transfo) {\parbox{2.5cm}{\centering transformation}};
\node (source tree root) {}
child { node {} }
child { node {}
child { node {} }
child { node {} }
};
\node (source tree) [draw, rectangle, fit=(source tree root) (source tree root-1) (source tree root-2-2), left=of transfo] {};
\node [block] (source document) [left=of source tree] {\parbox{2cm}{\centering source document}};
\node (stylesheet tree root) {}
child { node {}
child { node {} }
child { node {} }
}
child { node {}
child { node {} }
child { node {} }
};
\node (stylesheet tree) [draw, rectangle, fit=(stylesheet tree root) (stylesheet tree root-1-1) (stylesheet tree root-2-2), above=of transfo] {};
\node [block] (stylesheet document) [above=of stylesheet tree] {stylesheet};
\node (result tree root) {}
child { node {}
child { node {} }
child { node {} }
}
child { node {}
child { node {} }
child { node {} }
};
\node (result tree) [draw, rectangle, fit=(result tree root) (result tree root-1-1) (result tree root-2-2), right=of transfo] {};
\node [block] (result document) [right=of result tree] {\parbox{2cm}{\centering result document}};
\begin{scope}[shorten >=1pt]
\draw [->] (source document) edge (source tree);
\draw [->] (source tree) edge (transfo);
\draw [->] (transfo) edge (result tree);
\draw [->] (result tree) edge (result document);
\draw [->] (stylesheet document) edge (stylesheet tree);
\draw [->] (stylesheet tree) edge (transfo);
\end{scope}
\end{tikzpicture}
\end{document}