2

Is it possible to have pattern something like <[a-zA-Z0-9]></[a-zA-Z0-9]> to match each nodes in xslt stylesheet?

1 Answer 1

2

You wouldn't want to use regex. Just use a predicate to match tags (elements) that don't contain any child nodes...

<xsl:template match="*[not(node())]">
    ...
</xsl:template>

How do you want to classify elements that only have attributes (like <foo attr="bar"/>)?

If you don't want to classify elements that have attributes as a singleton, you would change the predicate to:

<xsl:template match="*[not(node()) and not(@*)]">
    ...
</xsl:template>
3
  • If I am not wrong, above predicate will also match empty elements ( like <foo attr="val"></foo>). How do I distinguish between them, or is it not possible?
    – Vix
    Dec 19, 2012 at 20:40
  • 1
    Yes because <foo attr="val"></foo> and <foo attr="val"/> are equivalent. There isn't a way to treat them differently in XSLT (because they're not different). Dec 19, 2012 at 20:47
  • Thanks Daniel. I was not certain about this. I will have to find another way to fix my issue, xslt won't help then.
    – Vix
    Dec 19, 2012 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.