• 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

XSLT Wrong Result Set?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys! I am new to XML and I have a file with a hierarchy as follows:

level-1
Level-2
Level-3
Level-4

I am running a XSLT(beloww) to extract info from level-4 and I am getting
also the level above. Can't I get only the Level-4 info without Leve2 and level-3 being displayed? What am I doing wrong?
Thanks guys.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<xsl:template match="Level-4">
<xsl:apply-templates select="Id"/>
</xsl:template>

<xsl:template match="Id">
<xsl:value-of select="."/><br />
</xsl:template>

</xsl:stylesheet>
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XSLT has a default set of rules which it applies whenever there is no template specified for a node. Approximately speaking, these default rules are to copy text nodes to the output and to apply templates to the children of element nodes. And it always starts processing at the root, which is why you are seeing text from those other elements in your output. If you insert this template you will come closer to your desired result:
reply
    Bookmark Topic Watch Topic
  • New Topic