• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is exactly happening here?

 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a stylesheet applied to an xml file. Can someone explain me clearly what is happening here. I'm a little confused. When i say
<xsl:template match="//city">,
i guess it selects all the city elements in the stylesheet.
===============================================
<?xml version="1.0" encoding="utf-8"?>
<country attr="100">USA
<state attr="200">Massachusetts
<city>Boston
<neighborhood>Back Bay</neighborhood>
<neighborhood>Roxbury</neighborhood>
<neighborhood>Jamaica Plain</neighborhood>
</city>
<city>Cambridge</city>
<city>Somerville</city>
<city>Northampton</city>
<city>Lowell</city>
</state>
<state>California
<city>Los Angeles
<neighborhood>Venice</neighborhood>
<neighborhood>Watts</neighborhood>
<neighborhood>Hollywood</neighborhood>
</city>
<city>Santa Monica</city>
<city>West Hollywood</city>
<city>Beverly Hiils</city>
</state>
</country>
===============================================
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> <xsl:template match="text()" />

<xsl:template match="//city[position()=1]">
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
================================================
Output --
<?xml version="1.0" encoding="UTF-8"?>
Boston
Los Angeles

=================================================
I guess there is a difference b/w
select="//city" and match="//city".
If so, does it mean that 'match' matches things in context?? and it something like select=".//city"??
Can someone please explain the reasons.
Thanks.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"If so, does it mean that 'match' matches things in context?? "
Yes, exactly and default to child nodes of the context node.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roseanne for the clarification.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<xsl:template match="//city[position()=1]">
This means: match any node called "city", anywhere in the hierarchy, if it is the first child of its parent.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic