ganesh0106 0 Newbie Poster

Hi All,

Many thanks for your response,

Actually you were given the coding looking good, what I gave the
input, but I want to change the input structure the xslt not working
properly.

Here I place one more sample input and output (please read command
instruction in output file) for your reference.

The input not a constant structure, some time <s1> to <s4> will be
changing. Can you correct the XSLT2.0, wherever I change
(insert/delete line) the input, the xslt2.0 coding will be working as
per the structure and output

This My xsl:
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:mf="http://example.com/2009/mf"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 exclude-result-prefixes="xs mf"
 version="2.0">

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="/*">
   <reg>
     <xsl:for-each-group select="*" group-starting-with="h2[@class eq
'LegP1GroupTitle']">
       <no>
         <xsl:value-of select="following-sibling::p[@class eq
'LegP1ParaText'][1]/span[@class eq 'LegP1No']"/>
       </no>
       <ti>
         <xsl:value-of select="."/>
       </ti>
       <xsl:for-each-group select="current-group() except ."
group-starting-with="p[@class eq 'LegP1ParaText']">
         <s1>
           <no>?</no>
           <pt>
             <xsl:value-of select="normalize-space(replace(.,
'\(\d+\)', ''))"/>
           </pt>
         </s1>
         <xsl:for-each-group select="current-group() except ."
group-starting-with="p[@class eq 'LegP2ParaText']">
           <s1>
             <no>?</no>
             <pt>
               <xsl:value-of select="replace(., '^\(\d+\)', '')"/>
             </pt>
             <xsl:sequence select="mf:group(current-group() except .,
3)"/>
           </s1>
         </xsl:for-each-group>
       </xsl:for-each-group>
     </xsl:for-each-group>
   </reg>
 </xsl:template>

 <xsl:function name="mf:group" as="element()*">
   <xsl:param name="els" as="element()*"/>
   <xsl:param name="n" as="xs:integer"/>
   <xsl:for-each-group select="$els" group-starting-with="p[@class eq
concat('LegP', $n, 'Container')]">
     <xsl:element name="s{$n - 1}">
       <no>
         <xsl:value-of select="span[@class eq concat('LegP', $n, 'No')]"/>
       </no>
       <pt>
         <xsl:value-of select="span[@class eq concat('LegP', $n,
'Text')]"/>
       </pt>
       <xsl:sequence select="mf:group(current-group() except ., $n + 1)"/>
     </xsl:element>
   </xsl:for-each-group>
 </xsl:function>

</xsl:stylesheet>
Input file
<root>
<h2 class="LegP1GroupTitle">Citation, commencement and application</h2>
<p class="LegP1ParaText">
<span class="LegP1No">1.</span>&#8212;(1) These Regulations may </p>
<p class="LegP2ParaText">(2) These Regulations shall </p>
<p class="LegP2ParaText">(3) These Regulations apply </p>
<p class="LegP3Container"><span class="LegP3No">(a)</span>
<span class="LegP3Text">xxxxxxxxxx </span>
<p class="LegP4Container"><span class="LegP4No">(i)</span>
<span class="LegP4Text">xxxxxxxxxx </span>

<h2 class="LegP1GroupTitle">Amendment of the Local </h2>
<p class="LegP1ParaText"><span class="LegP1No">2.</span>  The Local
Government</p>
<h2 class="LegP1GroupTitle">Amendment of the Local </h2>
<p class="LegP1ParaText"><span class="LegP1No">3.</span>  The Local
Government Pension </p>
<p class="LegP3Container"><span class="LegP3No">(a)</span>
<span class="LegP3Text">after regulation 36 (actuarial </span>
</p>
</root>
What I need:
<root>
<reg><no>1.&mdash;</no><ti>Citation, commencement and application</ti>
<s1><no>(1)</no><pt>These Regulations may </pt></s1>
<s1><no>(2)</no><pt>These Regulations shall </pt></s1>
<s1><no>(3)</no><pt>These Regulations apply </pt>
<s2><no>(a)</no><pt>xxxxxxxx </pt>
<s3><no>(i)</no><pt>xxxxxxxx </pt></s3></s2></s1></reg>
<reg><no>2.</no><ti>Amendment of the Local</ti>
<!--here not avilable &#8212;([0-9]), so here start only <pt>, not <s1>-->
<pt>The Local Government </pt></reg>
<reg><no>3.</no><ti>Amendment of the Local </ti>
<!--here not avilable &#8212;([0-9]), so here start only <pt>, not <s1>-->
<pt>The Local Government Pension </pt>
<!-- here not came s1 (0-9), so directly start s2-->
<s2><no>(a)</no><pt>after regulation 36 (actuarial </pt>

<!--
Note: if <p> will be start at
           (1) that's (0-9) is the para return as <s1> part
           (a) that's (a-z) is the para return as <s2> part
           (i) that's (roman letters) is the para return as <s3> part
           (aa) is the para return as <s4> part, totaly s4 levels only -->
</root>
Actually I get:
<reg>
           <no>1.</no>
           <ti>Citation, commencement and application</ti>
           <s1><no>?</no><pt>1.— These Regulations may</pt></s1>
           <s1><no>?</no><pt> These Regulations shall </pt></s1>
           <s1><no>?</no><pt> These Regulations apply </pt></s1>
</reg>
<reg>
           <no>2.</no><ti>Amendment of the Local </ti>
<s1><no>?</no><pt>2.  The Local Government</pt></s1>
</reg>
<reg>
           <no>3.</no>
           <ti>Amendment of the Local </ti>
           <s1><no>?</no><pt>3.  The Local Government Pension</pt></s1>
           <s1><no>?</no><pt>(a)after regulation 36 (actuarial </pt></s1>
</reg>

Thanks,
Selva

----------------------------------------

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.