Start New Discussion within our Software Development Community

Hi,

I want to process the following xml:
...
<a>
HHHHeader 1 : xxx <it> yyy </it> zzz
HHHHeader 2 : aaa bbb <it> ccc </it>
</a>
...

And I want to get via a xslt the following xml

...
<a>
<Header hd="1">
xxx <it> yyy </it> zzz
</Header>
<Header hd="2">
aaa bbb <it> ccc </it>
</Header>
</a>
...


Using code like this
<xsl:template match="a">

<xsl:variable name="elValue" select="."/>

<xsl:analyze-string select="$elValue"
regex="HHHHeader ([0-9]*)\s:([\s\S]*)">

<xsl:matching-substring>
<xsl:element name="Header">
<xsl:attribute name="hd" select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
</xsl:element>
</xsl:matching-substring>

<xsl:non-matching-substring>
<aInError>
<xsl:value-of select="$elValue"/>
</aInError>
</xsl:non-matching-substring>

</xsl:analyze-string>

</xsl:template>

I know how to create the following xml

<a>
<Header hd="1">
xxx yyy zzz
</Header>
<Header hd="2">
aaa bbb ccc
</Header>
</a>

but then the <it> nodes are lost. I have no clue how I could proceed to keep these. Anyone can help ?

Thanx

For those interested in a solution: in using the same string/regexp analysis approach while looping recursively (using apply-templates) on the text and <it> nodes until the next "Header" occurs in a text node I managed to do it.

Thanks.

This question has already been answered. Start a new discussion instead.