Nested ID Generation: Heading

"Ramkumar" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Organization PMG
Message-ID <[email protected]>
Hi List,

I need to generate id for different heading levels like below pattern.

<H1>	<H1 id="s1">
<H2>		s1a
<H2>		s1b
<H3>		s1b1
<H3>		s1b2
<H2>		s1c
<H2>		s1d
<H1>		s2

<H1>	<H1 id="s1">
<H2>		s1a
<H3>		s1a1
<H4>		s1a1a
<H5>		s1a1a1
<H1>		s2

Here, H1.H5 are element of input XML file.
H1 id="s1",,, are required XML file with IDs.

I have tried using perl as below,

#ID Generation for section
	my $secseq=1;
	while($xml=~m/<section1>.+?<\/section1>/msi)
	{
		my $secseq2="a";
		my $secseq3=0;
		my $secseq4="a";
		my $secseq5=0;
		my $section=$&;
		$section=~s/<section1>/"<section
local-id=\"".$chap."s".$secseq."\">"/egs;#	local-id="c01s1">
		$section=~s/<section2>/"<section
local-id=\"".$chap."s".$secseq.$secseq2++."\">"/egs;	#local-id="c01s1a">
		$section=~s/<section3>/"<section
local-id=\"".$chap."s".$secseq.$secseq2++.++$secseq3."\">"/egs;
#local-id="c01s1a1">
		$section=~s/<section4>/"<section
local-id=\"".$chap."s".$secseq.$secseq2++.++$secseq3.$secseq4++."\">"/egs;
#local-id="c01s1a1s">
		$section=~s/<section5>/"<section
local-id=\"".$chap."s".$secseq.$secseq2++.++$secseq3.$secseq4++.++$secseq5."
\">"/egs;	#local-id="c01s1a1s1">
		$xml=~s/<section1>.+?<\/section1>/$section/msi;
	$secseq++;
	}

Please any one share the logic to get the above output.

Regards,
Ramkumar

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.