• 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 related Question

 
Greenhorn
Posts: 25
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my xml file is the following :


My expected output xml is the following :


My xslt code is as follows :


But the actual output is

My question is why is it getting abc ?
Why is it not working properly?
 
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
This line of code:



tells the XSLT processor to apply its rules to all children of the root element, because it's called when the root element is being processed. You've provided a rule for anything matching "work/cd", so that gets called for each of your work/cd elements. And that's what you want. But the other children of the root element, you haven't provided any rules. So the XSLT processor applies its default rules.

Roughly speaking (because I haven't looked up the exact details) the default processing rules are these:

  • For an element node, apply the processing rules to each child successively.
  • For a text node, write the contents of the node to the output.


  • And the rules are applied recursively. So first it finds an <abc> element and applies the rules... which means it applies the rules to the <xyz> child... I leave you to work out how it goes from there.

    I expect you also want to know what to do about it. Well, just don't apply-templates to all children in that line of code. Use its "select" attribute to say which children you want to apply templates to.
     
    Koushik Ghosh
    Greenhorn
    Posts: 25
    Eclipse IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks..that helps. I didn't know what were the default processing rules.
    However I solved the problem by putting <xsl:template match="text()"/> in the code.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic