Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xslt xml html: how to distinguish the same elements with or without child?

Tags:

html

xml

xslt

The problem is I want to distinguish same elements name with different situation. For example:

<element>Hello StackOverFlow</element>
<element>
  <group>
     <ge>hello g1</ge>
     <ge>hello g2</ge>
  </group>
  <group>
     <ge>hello g3</ge>
     <ge>hello g4</ge>
  </group>
</element>

I want to have elements with text convert into

<div class="text_element">Hello StackOverFlow</div>

and for those elements with child nodes:

<div class="element">
  <ul class="group">
     <li>hello g1</li>
     <li>hello g2</li>
  </ul>
  <ul class="group">
     <li>hello g3</li>
     <li>hello g4</li>
  </ul>
</div>

So, the problem is how can I distinguish these two kind of elements in writing the template?

like image 716
KAI Avatar asked Dec 05 '25 08:12

KAI


1 Answers

One simple way: write one template with match="element[normalize-space(text())]" and one with match="element[*]. The first matches element elements with text-node children that aren't just whitespace; the second matches element elements with element children.

like image 198
C. M. Sperberg-McQueen Avatar answered Dec 07 '25 23:12

C. M. Sperberg-McQueen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!