Search code examples
xmlxsltxslt-2.0

XML/XSLT: Style similar tagging scenarios differently


I have two scenarios where I use the <b> tag within a <p> tag in XML:

  1. The <p> tag contains plain text and an occasional <b> tag (typical use):
<p>This is a sentence with a <b>bold</b> word.</p>
  1. The <p> tag only contains the <b> tag:
<p><b>This is a subsection title</b></p>

Can I use XSLT 2.0 to change the font size of the <b> tag in scenario 2 only?

I'm aware that I could easily use the outputclass attribute and style with CSS, but long story short, this isn't sufficient for my needs.


Solution

  • A template matching p[not(text())]/b will process only those b elements that do not have any sibling text nodes.