posted 21 years ago
Shan,
I think if you get the point of differentiating b/w "/" and "//", things will be a piece of cake for you. Here we go,
Here is some terminology to consider -
"/" ---> This is the document root when used at the begining as in "/source"; this looks for the root element child(source in this case)right under the document root; again this depends on the context under which it has been used; please look at the example below -
/source/AAA --> the second "/" in this xpath expression before AAA says that get all the children (only first level children) under the source.
Little example -
<source>
<AAA/>
<AAA/>
<BBB>
<AAA/>
</BBB>
</source>
/source/AAA gets only the first two AAA (not the one inside BBB), while /source//AAA gets all the AAA children under source irrespective of the level of nesting.
Now with this footing, let's look at the real thing -
I got this stuff pasted from the actual example stylesheet in the link provided -
<xsl:apply-templates select="/source//AAA/BBB//*"/>
Please look at the xml below (copied from the link u provided) -
==============================================
<source>
<AAA id="a1" pos="start">
<BBB id="b1"/>
<BBB id="b2"/>
</AAA>
<AAA id="a2">
<BBB id="b3"/>
<BBB id="b4"/>
<CCC id="c1">
<DDD id="d1"/>
</CCC>
<BBB id="b5">
<CCC id="c2"/>
</BBB>
</AAA>
</source>
================================================
This means that get all the AAA descendants (not merely the immediate children)of the source (root element), then for each AAA in that list, get the immediate BBB children (not all the descendants) and get all the children (*) for these BBB elements. The only node that matches this xpath expression is the CCC shown below in its context -
<BBB id="b5">
<CCC id="c2"/>
</BBB>
Hope that this is clear. Please try to play around with the XML document by nesting more elements within each other and try changing the xpath expression and see the results by applying the stylesheet. This will make things much clearer.