• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

select="//Item" and select=".//Item"

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone kindly explain what is the difference between
select="//Item" and select=".//Item"
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//Item means all the "Item" elements from the root node of the tree. ".//Item" means all the ones below the current context ".".
Please have a look at the following example (both sample xml and xslt files are given) and try replacing the following line relevantly to see the difference. Other attribute names are intuitive.
<xsl:for-each select="//Item">
AND
<xsl:for-each select=".//Item">
=================================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Document">
<xsl:for-each select="//Item">
<p>
<xsl:value-of select="@attr"/>
</p>
</xsl:for-each>
</xsl:template>
<!-- Supress unwanted text output from default templates -->
<xsl:template match="text()"/>
</xsl:stylesheet>
=================================================
<root>
<element1 attr="level1">
<Item attr="level2_firstItem">
<Document attr="level3">
<Item attr="level4_firstItem"/>
<Item attr="level4_secondItem"/>
</Document>
</Item>
<Item attr="level2_secondItem"/>
</element1>
<element2 attr="level1"/>
<element3 attr="level1"/>
<Item attr="level1_firstItem"/>
</root>
=================================================
 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a very comprehensive reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic