I have an existing xslt file that I've created before with several templates.
Now, the requirements have changed and now before processing one of these specific templates I have to check if the current evaluating node has a specific attribute or not.
If yes, another template has to be called first and then the specific one.
So basically my input XML looks like this:
<baseNode>
<textgroup>
<title>Title here</title>
<text specAttr="id123456">Text here</text>
<text>Another text</text>
</textGroup>
<paragraph specAttr="id123456">Other text here</paragraph>
</baseNode>
Now, parsing the XML file, the result should be something like this:
<base>
<title>Title here</title>
<text>Next text has this attribute</text>
<text>Text here</text>
<text>Another text</text>
<text>Next text has this attribute</text>
<p>Other text here</p>
</base>
Well...there are several elements in the XML that can have this attribute 'specAttr' and I don't want to change each existing <xsl:template> to check for this attribute as well...
I tried to add a <xsl:template match="*"> which did that job and hoped it will match for each element before the specific template of this element is processed. But it seems as if this only works for nodes that does not a specific xsl:template defined.
I've also already read here that it is possible to create templates matching attributes with <xsl:template match="@specAttr">, but this template is only parsed if I add <xsl:apply-templates select="@*"/>. So I would also have to change each already existing template and add this line.
Is it possible to create something like a template-hierarchy or inheritance between templates? That always the parent template would be processed before the actual templat e of the current node?
Or does anyone have another smart idea?
If you need more information or have questions, please don't hesitate to ask.
Thanks in advance.
BRgrds, Jens
No comments:
Post a Comment