• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT related Question

 
Koushik Ghosh
Greenhorn
Posts: 25
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Clapham
Sheriff
Posts: 21586
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic