File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XSLT related Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT related Question" Watch "XSLT related Question" New topic

XSLT related Question

Koushik Ghosh

Joined: May 26, 2013
Posts: 25

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

Joined: Oct 14, 2005
Posts: 19973

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

    Joined: May 26, 2013
    Posts: 25

    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.
    I agree. Here's the link:
    subject: XSLT related Question
    jQuery in Action, 3rd edition