Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

know if current() is a element or an attribute

Tags:

xml

xslt

xpath

Working on an XSLT sheet, I end up in a template with some current() xpath. I would like to know if it refers to an attribute or to an element.

Actually, I do not manage to do what I want using the template filters select="./@*"or select="./*", because I want to get all the elements or attributes in one shot, and apply a different treatment depending on the type, in the same template.

like image 857
Sylvain B. Avatar asked Oct 25 '25 04:10

Sylvain B.


1 Answers

It sounds rather as if you want to set up different templates for the different nodes with e.g. match="* and match="@*".

If you really want to check inside a template then you can use <xsl:if test="self::*"> to test whether it is an element node and in XSLT 2 and later also with <xsl:if test="self::attribute()"> whether it is an attribute. In XSLT/XPath 2 and later there is also the . instance of element() respectively . instance of attribute() test.

like image 183
Martin Honnen Avatar answered Oct 26 '25 23:10

Martin Honnen