Hi, Does the order of declaring templates in XML has any significance in processing order of these templates? My XML contains templates in following oder:
If the source html contains <u><strong><em> tag in same order as in XML the tags are processed correctly, but if the order differs, the templates are not processed correctly. Say if order is <u><em><strong> then the em template is processed twice. I think am making some fundamental mistake here as I haven't read anywhere that templates are processed in the order they are declared. Thanks, Kapil
Well, as I read section 5.5 of the XSTL Recommendation, all of those three templates have the same priority (because they are all of the same form). So the rule for choosing among the three is this:
It is an error if this leaves more than one matching template rule. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matching template rules that are left, the one that occurs last in the stylesheet.
Ok, But What I could not understand is if the source content contains a tag say, strong and there is a template defined with match="strong//text()", then why the processor tries to process template with maximum priority and if the priority is same then it processes the last one again? regards, kapil
I have no idea. I can't even see why it works the way you say it does. As far as I can see, the first thing that should happen is that the pattern "u//text()" matches a text node, and you produce a <RICHTEXT UNDERLINE="true"> element containing that text. From there on the xsl:apply-templates shouldn't match anything, because the text node doesn't have any children to apply to.
Edit: You said "If the source html contains <u><strong><em> tag..." and I took that to mean exactly what it said. That is, I took it to mean that you didn't mention the end tags and you had something like <u><strong><em>some text</em></strong></u>. But it's possible that you were really talking about elements and just using sloppy terminology calling them tags. In that case you would have something like <u>some text</u><strong>some text</strong><em>some text</em>. In which case your templates make a bit more sense.
Okay. Let's go with the misleading terminology idea. All your templates say is "When you see a <u> element do this" and so on. So there aren't any instances when two of those templates will match a single text node, so what I said in my first reply is irrelevant.
The first template (span//text()) does nothing except to prevent span elements from producing anything in the output. Calling xsl:apply-templates in it does nothing because the text node it selects can't have any children.
So I don't see where the other templates are being called from. Possibly they are being called via the build-in processing rules. [ April 20, 2007: Message edited by: Paul Clapham ]
Originally posted by kapil Gupta: So if both strong and italic is applied to a text, I have to set two attribute s of richtext node.
Well, the XSLT you posted isn't going to do that regardless of your questions about the order of things. It's going to generate one RICHTEXT element for each strong element in the input, and one RICHTEXT element for each em element in the input. Or at most it will generate that, depending on whether your xsl:apply-templates even finds those elements. There's no way it can generate one RICHTEXT element with two attributes, if that was your intention.
And by the way when your template matches a text node (like all the ones you posted do) there is no point in calling xsl:apply-templates inside it, because the text node has no children to apply templates to anyway.