tags:

views:

44

answers:

1

Hi, I have the following xml and I'm writing a XSLT to transform it:

<callop>
 <con>unit</con>
 <var>u</var>
 <var>v</var>
</callop>

The problem is that if <callop> is inside <is> then it should be a <nano> element and <con> becomes <Fun> but otherwise its an <Atom> and <con> becomes a <Rel>.

How is this possible. Do I have to go and check what the parent node is? I appreciate some help.

Thanks

+3  A: 

You can handle this pretty easily by just specifying your templates with the full path. The more specific template match will take precedence, so there shouldn't be any issues.

<xsl:template match="is/callop">
   <nano>
     ...
...

<xsl:template match="callop">
   <Atom>
     ...
...
nullptr
What about the '<con>' element inside '<callop>' what happens to that?
You can declare a separate template "is/callop/con" to match it and use apply-templates from the "is/callop" template, or just handle it inline, e.g.: <Fun><xsl:apply-templates select="con" /></Fun>
nullptr
Thankyou. It works fine now.