943,806 Members | Top Members by Rank

Ad:
Sep 20th, 2009
-1

How to add an enclosing node to text including nodes?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikeHL is offline Offline
2 posts
since Sep 2009
Sep 22nd, 2009
-1

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikeHL is offline Offline
2 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: [XSLT] Group tags to prioritize the xml file
Next Thread in XML, XSLT and XPATH Forum Timeline: include, call-template





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC