xml - Sublist format text inside label as attributes -
i want add label inside para attribute value:
my source xml:
<body> <p>blahblah</p> <ul outputclass="l1"> <li outputclass="lt1">(a) blahblah</li> <li outputclass="lt1">(b) blahblah</li> <li outputclass="lt1">(c) blahblah <ul outputclass="l2"> <li outputclass="lt2"> (1) blahblah</li> <li outputclass="lt2"> (2) blahblah<fn><p>blah</p></fn></li> <li outputclass="lt2"> (3) blahblah <ul outputclass="l3"> <li outputclass="lt3"> (i) blahblah<fn><p>blah</p></fn></li> <li outputclass="lt3"> (ii) blahblah</li> <li outputclass="lt3"> (iii) blahblah</li> </ul></li> </ul></li> <li outputclass="lt1">(d) blahblah</li> <li outputclass="lt1">(e) blahblah</li> </ul> <p>blahblah</p> </body>
myxslt
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="@* | node()" mode="#all"> <xsl:copy> <xsl:apply-templates select="@* | node()" mode="#current"/> </xsl:copy> </xsl:template> <xsl:template match="p"> <para> <xsl:apply-templates/> </para> </xsl:template> <xsl:template match="ul[@outputclass='l1'] | ul[@outputclass='l2'] | ul[@outputclass='l3']"> <itemizedlist type="•"> <xsl:apply-templates/> </itemizedlist> </xsl:template> <xsl:template match="li[@outputclass='lt1'] | li[@outputclass='lt2'] | li[@outputclass='lt3']"> <item> <xsl:for-each-group select="node()" group-adjacent="boolean(self::ul)"> <xsl:choose> <xsl:when test="current-grouping-key()"> <xsl:apply-templates select="current-group()"/> </xsl:when> <xsl:otherwise> <para> <xsl:apply-templates select="current-group()" mode="preserve"/> </para> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </item> </xsl:template> </xsl:stylesheet>
output getting para inside labels:
<body> <para>blahblah</para> <itemizedlist type="normal"> <item><para>(a) blahblah</para></item> <item><para>(b) blahblah</para></item> <item><para>(c) blahblah</para> <itemizedlist type="normal"> <item><para> (1) blahblah</para></item> <item><para> (2) blahblah</para></item> <item><para> (3) blahblah<footnote><para>blah</para></footnote></para> <itemizedlist type="normal"> <item><para> (i) blahblah<footnote><para>blah</para></footnote></para></item> <item><para> (ii) blahblah</para></item> <item><para> (iii) blahblah</para></item> </itemizedlist></item> </itemizedlist></item> <item><para>(d) blahblah</para></item> <item><para>(e) blahblah</para></item> </itemizedlist> <para>blahblah</para> </body>
but needed output para inside label values 'a. or (a) or a) or a) or (a) or a. or i) or (i) or i.' have removed , add item tag attribute num value shown below :
<body> <para>blahblah</para> <itemizedlist type="normal"> <item num="(a)"><para>blahblah</para></item> <item num="(b)"><para>blahblah</para></item> <item num="(c)"><para>blahblah</para> <itemizedlist type="normal"> <item num="(1)"><para>blahblah</para></item> <item num="(2)"><para>blahblah</para></item> <item num="(3)"><para>blahblah<footnote><para>blah</para></footnote></para> <itemizedlist type="normal"> <item num="(i)"><para>blahblah<footnote><para>blah</para></footnote></para></item> <item num="(ii)"><para>blahblah</para></item> <item num="(iii)"><para>blahblah</para></item> </itemizedlist></item> </itemizedlist></item> <item num="(d)"><para>blahblah</para></item> <item num="(e)"><para>blahblah</para></item> </itemizedlist> <para>blahblah</para> </body>
please suggest me
thanks in advance.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="@* | node()" mode="#all"> <xsl:copy> <xsl:apply-templates select="@* | node()" mode="#current"/> </xsl:copy> </xsl:template> <xsl:template match="p"> <para> <xsl:apply-templates/> </para> </xsl:template> <xsl:template match="ul[@outputclass='l1'] | ul[@outputclass='l2'] | ul[@outputclass='l3']"> <itemizedlist type="•"> <xsl:apply-templates/> </itemizedlist> </xsl:template> <xsl:template match="li[@outputclass='lt1'] | li[@outputclass='lt2'] | li[@outputclass='lt3']"> <item> <xsl:for-each-group select="node()" group-adjacent="if(self::text()) then('text') else(generate-id())"> <xsl:choose> <xsl:when test="self::ul"> <xsl:apply-templates select="current-group()"/> </xsl:when> <xsl:when test="current-grouping-key() = 'text' , position() = 1"> <xsl:attribute name="num" select="tokenize(normalize-space(current-group()), ' ')[1]"/> <para> <xsl:value-of select="string-join(tokenize(normalize-space(current-group()), ' ')[position() > 1], ' ')"/> </para> </xsl:when> <xsl:otherwise> <para> <xsl:apply-templates select="current-group()" mode="preserve"/> </para> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </item> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment