creep3007
creep3007

Reputation: 13

problems by xslt hive off child-nodes in correct oder

I've some problems by transforming my xml. I'ld like to hive-off child-node in correct order.

Current nesting of elements ( / nodes)

<span style="font-family: [Ohne];">
   <span style="font-family: qwe;">etu</span>
   <!-- hive off this nested child-node above the parent -->
   restia volorsin  
</span>

Intended nesting and order of elements (/ nodes)

<!-- after xslt -->
<span style="font-family: [Ohne];">restia volorsin</span>
<span style="font-family: qwe;">etu</span>

see more example code

Could anyone gave me some tips?

Upvotes: 1

Views: 165

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243549

As easy as this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="span[span]">
  <xsl:copy>
       <xsl:copy-of select="@*|node()[not(self::span)]"/>
  </xsl:copy>
  <xsl:copy-of select="span"/>
 </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the provided XML document:

<span style="font-family: [Ohne];">
   <span style="font-family: qwe;">etu</span>
   <!-- hive off this nested child-node above the parent -->
   restia volorsin
</span>

the wanted, correct result is produced:

<span style="font-family: [Ohne];"><!-- hive off this nested child-node above the parent -->
   restia volorsin
</span>
<span style="font-family: qwe;">etu</span>

Upvotes: 1

Related Questions