Why is $p^{-1}(f(X')) \cong X' \times_X Z$? Assume $f:X'\rightarrow X$ is a morphism of $S$ schemes,the map is a homeomorphism onto its image, for each point of $X'$,$f^{\sharp}_{x'}:\mathcal{O}_{X,f(x')}\rightarrow \mathcal{O}_{X',x'}$is bijective. $p$ is the canonical projection from $Z=X \times_S Y$ to $X$, how do we show the scheme $(p^{-1}(f(X')),\mathcal{O}_{Z|p^{-1}f(X)})$ is the fiber product of $Z$ and $X'$ over $X$ in the category of locally ringed spaces? 
My problem is that I cannot construct the morphism  $(p^{-1}(f(X')),\mathcal{O}_{Z|p^{-1}}f(X))$ to $X'$ . Since there is natural $\mathcal{O}_X$ to $\mathcal{O}_{Z|p^{-1}f(X)}$, I only need to construct $\mathcal{O}_X'$ to $\mathcal{O}_X$.
And I do not know how to show the inverse image has universal property,mainly about the universal property of that sheaf. And I don't know how the isomorphism is used here?
(Gortz and Wedhorn Algebraic Geometry I, p102, prop 4.20(1))
 A: Disclaimer: At the moment my answer only holds under the additional hypothesis that $f$ is an open immersion.
The key ingredient you will need is the following:


An open immersion in the category of schemes is a monomorphism.


Proof: Suppose $W$ is some other scheme and we have morphisms $g_1 : W \to X'$, $g_2: W\to X'$ such that $f \circ g_1 = f \circ g_2$. At the level of topological spaces immediately this gives that $g_1 = g_2$ because $f$ is injective on points. Now we need to see that $g_1 = g_2$ as morphisms of schemes. It is enough to show $g_1^\sharp = g_2^\sharp$. I leave this as an exercise for you (Hint: It is enough to show an equality on stalks).
With this result in hand we can now prove:


Let $f : X' \to X$ be an open immersion of schemes and $p : Z \to X$  any morphism. Then $X' \times_X Z \cong p^{-1}(f(X'))$. 


Proof: Because $f$ is an open immersion, $p^{-1}(f(X'))$ is an open subset of  $Z$, in fact we have a canonical open immersion $i : p^{-1}(f(X')) \to Z$. Now suppose $W$ is some other scheme and we have maps $g_1: W\to Z$,$g_2:W\to X'$ such that $f \circ g_2 = p \circ g_1$. Then this says that the image of $g_1$ lands in $p^{-1}(f(X'))$, i.e. that $g_1$ factors through $p^{-1}(f(X'))$ via some map $h$. If we had two $h_1,h_2: W\to p^{-1}(f(X'))$ that made a relevant diagram commute, we would have
$$i \circ h_1 = i \circ h_2.$$
But now $i$ is a monomorphism so this implies $h_1 = h_2$ so the factoring is unique. In other  words, we have shown $p^{-1}(h(X'))$ satisfies the universal property of the fibered product $X'\times_X Z$.
A: If I am not mistaken, to show that $p^{-1}(f(X'))$  completes a cartesian diagram with $X'\to X, X\times_S Y \to X$, it is enough to show that this is true in (Set). 
The assertion that  $p^{-1}(f(X')$ is the fibered product in (Sets) follows from f being injective.
