xslt - Flatten nested XML including body text -


i transform xhtml fragments particular xml form subsequent processing. achieve xslt.

i have seen questions , answers here on flattening nested xml structures, nothing obvious included multiple element body text nodes, so...

the example input xhtml follows (this example simplest case, in theory can have level of nesting of spans different class attributes):

<div>     <span class="one">         leading 1 text         <span class="two">two text</span>         trailing 1 text     </span> </div> 

i trying generate output xml:

<document>     <text class="one">leading 1 text </text>     <text class="two">two text</text>     <text class="one"> trailing 1 text</text> </document> 

can achieved xslt, , if so, how?

<xsl:template match="div">   <document>     <xsl:apply-templates select=".//text()[normalize-space() != '']" />   </document> </xsl:template>  <xsl:template match="div//text()">   <text class="{../@class}">     <xsl:value-of select="normalize-space()" />   </text> </xsl:template> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -