Reputation: 11065
I am learning xslt. I am trying to understand some xslt codes, but am not getting what the following line of code means:
<xsl:variable name="Product" select="document('ProductList.xml')/node()[1]/node()[2]/node()[2]/node()[2]"/>
I can understand the variable will be "$Product", but i am unable to understand the value of the select attribute, the '/'s and nodes()[] after the document function. I have coding knowledge of c# and java and i am not familiar with this type of syntax. I would like to know what these '/'s mean in the value of the select.
Upvotes: 0
Views: 807
Reputation: 2454
Reading backwards :-
node()[2], node()[2], node()[2], node()[1], document('ProductList.xml')
second child of, second child of, second child of, first child of, ProductList.xml document
Upvotes: 0
Reputation: 101748
The select
attribute is an indication that the variable's value should be determined by an XPath expression.
The document('ProductList.xml')
loads the file with the name "ProductList.xml" to perform an XPath selection on it.
The /node()[1]/node()[2]/node()[2]/node()[2]
part means that the 2nd child of the 2nd child of the 2nd child of the 1st element should be selected. In other words, if ProductList.xml looked like this:
<a> <!-- /node()[1] -->
<b> <!-- /node()[1]/node()[1] -->
<c /> <!-- /node()[1]/node()[1]/node()[1] -->
<d /> <!-- /node()[1]/node()[1] -->
</b>
<e> <!-- /node()[1]/node()[2] -->
<f /> <!-- /node()[1]/node()[2]/node()[1] -->
<g> <!-- /node()[1]/node()[2]/node()[2] -->
<h /> <!-- /node()[1]/node()[2]/node()[2]/node()[1] -->
<i /> <!-- /node()[1]/node()[2]/node()[2]/node()[2] -->
</g>
</e>
</a>
Then that XPath would select the <i>
node, which is the second child of <g>
, which is the second child of <e>
, which is the second child of <a>
, which is the 1st (and only) root element.
Upvotes: 5