How to add an enclosing node to text including nodes?

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2009
Posts: 2
Reputation: mikeHL is an unknown quantity at this point 
Solved Threads: 0
mikeHL mikeHL is offline Offline
Newbie Poster

How to add an enclosing node to text including nodes?

 
-1
  #1
Sep 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 2
Reputation: mikeHL is an unknown quantity at this point 
Solved Threads: 0
mikeHL mikeHL is offline Offline
Newbie Poster

Re: How to add an enclosing node to text including nodes?

 
0
  #2
Sep 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC