xml - Tagging hierarchy using xslt input as table format -
how hierarchy of tagging table format input
my input xml:
<?xml version="1.0" encoding="utf-8"?> <topic outputclass="toa_entries"> <title outputclass="toa_e">table of authorities – entries</title> <body> <table frame="all" outputclass="tablegrid0"> <tgroup cols="2"> <colspec colname="col1" colwidth="130.50pt"/> <colspec colname="col2" colwidth="245.50pt"/> <tbody> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_title">structures</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l1">carnivanal code (26 u.s.c.)</p> </entry> </row> <row> <entry> <p id="p_s_irc_ch61" outputclass="toa_id">s_irc_ch61</p> </entry> <entry> <p outputclass="toa_entry_l1">ch. 61</p> </entry> </row> <row> <entry> <p id="p_s_irc_irc1931" outputclass="toa_id">s_irc_irc1931</p> </entry> <entry> <p outputclass="toa_entry_l1">i.r.c. of 1931</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l1">investment company act of 1940</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l2">rules</p> </entry> </row> <row> <entry> <p id="p_s_ica_r_ica1940" outputclass="toa_id">s_ica_r_ica1940</p> </entry> <entry> <p outputclass="toa_entry_l1">202(a)(11)(g)-1</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l1">securities act of 1933</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l2">rules</p> </entry> </row> <row> <entry> <p id="p_s_sa_r_sa1933" outputclass="toa_id">s_sa_r_sa1933</p> </entry> <entry> <p outputclass="toa_entry_l1">202(a)(30)-1(a)</p> </entry> </row> <row> <entry> <p id="p_s_sa_r_sa1933_1" outputclass="toa_id">s_sa_r_sa1933_1</p> </entry> <entry> <p outputclass="toa_entry_l1">202(a)(30)-1(a)(1)</p> </entry> </row> </tbody> </tgroup> </table> <table frame="all" outputclass="tablegrid0"> <tgroup cols="2"> <colspec colname="col1" colwidth="130.50pt"/> <colspec colname="col2" colwidth="247.50pt"/> <tbody> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_title">cases</p> </entry> </row> <row> <entry> <p id="p_c_3mcovbrowner" outputclass="toa_id">c_3mcovbrowner</p> </entry> <entry> <p outputclass="toa_entry_l1">3m co. v. browner</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l1">a</p> </entry> </row> <row> <entry> <p id="p_c_abbatevus" outputclass="toa_id">c_abbatevus</p> </entry> <entry> <p outputclass="toa_entry_l1">abbate v. united states</p> </entry> </row> <row> <entry> <p id="p_c_abelvus" outputclass="toa_id">c_abelvus</p> </entry> <entry> <p outputclass="toa_entry_l1">abel v. united states</p> </entry> </row> <row> <entry namest="col1" nameend="col2"> <p outputclass="toa_text_l1">b</p> </entry> </row> <row> <entry/> <entry> <p outputclass="toa_entry_l1">bacon v. comm’r</p> </entry> </row> <row> <entry> <p id="p_c_baconvcommr1" outputclass="toa_id">c_baconvcommr1</p> </entry> <entry> <p outputclass="toa_entry_l2">september 1, 1982</p> </entry> </row> <row> <entry> <p id="p_c_baconvcommr2" outputclass="toa_id">c_baconvcommr2</p> </entry> <entry> <p outputclass="toa_entry_l2">january 8, 1984</p> </entry> </row> <row> <entry> <p id="p_c_compaqcompvcommr" outputclass="toa_id">c_compaqcompvcommr</p> </entry> <entry> <p outputclass="toa_entry_l1">compaq computer corp. v. comm’r</p> </entry> </row> </tbody> </tgroup> </table> </body> </topic>
the xslt using:
<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0"> <xsl:output method="html" doctype-public="xslt-compat" omit-xml-declaration="yes" encoding="utf-8" indent="yes" /> <xsl:template match="@* | node()" name="identity" priority="1"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']" priority="25"> <toa type="toa"> <xsl:apply-templates/> </toa> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/title[@outputclass='toa_e']" priority="25"> <title> <xsl:apply-templates/> </title> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']" priority="118"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup" priority="119"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/colspec" priority="120"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody" priority="121"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row" priority="122"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry" priority="123"> <xsl:apply-templates/> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody" priority="124"> <toa-section> <xsl:apply-templates/> </toa-section> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_title']" priority="125"> <title> <xsl:apply-templates/> </title> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_text_l1']" priority="126"> <toa-div level="div1"> <title><xsl:apply-templates/></title> </toa-div> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_text_l2']" priority="127"> <toa-div level="div2"> <title><xsl:apply-templates/></title> </toa-div> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_entry_l1']" priority="127"> <xsl:element name="toa-entry"> <primary-entry> <entry-name> <xsl:apply-templates/> </entry-name> </primary-entry> </xsl:element> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_entry_l2']" priority="127"> <secondary-entry> <entry-name> <xsl:apply-templates/> </entry-name> </secondary-entry> </xsl:template> <xsl:template match="topic[@outputclass='toa_entries']/body/table[@outputclass='tablegrid0']/tgroup/tbody/row/entry/p[@outputclass='toa_id']" priority="126"> </xsl:template> </xsl:transform>
i getting output this:
<!doctype html public "xslt-compat"> <toa type="toa"> <title>table of authorities – entries</title> <body> <toa-section> <title>structures</title> <toa-div level="div1"> <title>carnivanal code (26 u.s.c.)</title> </toa-div> <toa-entry> <primary-entry> <entry-name>ch. 61</entry-name> </primary-entry> </toa-entry> <toa-entry> <primary-entry> <entry-name>i.r.c. of 1931</entry-name> </primary-entry> </toa-entry> <toa-div level="div1"> <title>investment company act of 1940</title> </toa-div> <toa-div level="div2"> <title>rules</title> </toa-div> <toa-entry> <primary-entry> <entry-name>202(a)(11)(g)-1</entry-name> </primary-entry> </toa-entry> <toa-div level="div1"> <title>securities act of 1933</title> </toa-div> <toa-div level="div2"> <title>rules</title> </toa-div> <toa-entry> <primary-entry> <entry-name>202(a)(30)-1(a)</entry-name> </primary-entry> </toa-entry> <toa-entry> <primary-entry> <entry-name>202(a)(30)-1(a)(1)</entry-name> </primary-entry> </toa-entry> </toa-section> <toa-section> <title>cases</title> <toa-entry> <primary-entry> <entry-name>3m co. v. browner</entry-name> </primary-entry> </toa-entry> <toa-div level="div1"> <title>a</title> </toa-div> <toa-entry> <primary-entry> <entry-name>abbate v. united states</entry-name> </primary-entry> </toa-entry> <toa-entry> <primary-entry> <entry-name>abel v. united states</entry-name> </primary-entry> </toa-entry> <toa-div level="div1"> <title>b</title> </toa-div> <toa-entry> <primary-entry> <entry-name>bacon v. comm’r</entry-name> </primary-entry> </toa-entry> <secondary-entry> <entry-name>september 1, 1982</entry-name> </secondary-entry> <secondary-entry> <entry-name>january 8, 1984</entry-name> </secondary-entry> <toa-entry> <primary-entry> <entry-name>compaq computer corp. v. comm’r</entry-name> </primary-entry> </toa-entry> </toa-section> </body> </toa>
needed output format below 2 formats
inside 'toa-div' neeed 'toa-entry' , inside 'toa-entry' need 'primary-entry' , 'secondary-entry' elements shown below output format.
if direct toa_title came in input xml need 'toa-div' , 'title' self close format shown below output format.
<!doctype html public "xslt-compat"> <toa type="toa"> <title outputclass="toa_e">table of authorities – entries</title> <body> <toa-section> <title>structures</title> <toa-div level="div1"> <title>carnivanal code (26 u.s.c.)</title> <toa-entry id="s_irc_ch61"> <primary-entry> <entry-name>ch. 61</entry-name> </primary-entry> </toa-entry> <toa-entry id="s_irc_irc1931"> <primary-entry> <entry-name>i.r.c. of 1931</entry-name> </primary-entry> </toa-entry> </toa-div> <toa-div level="div1"> <title>investment company act of 1940</title> <toa-div level="div2"> <title>rules</title> <toa-entry> <primary-entry id="s_ica_r_ica1940"> <entry-name>202(a)(11)(g)-1</entry-name> </primary-entry> </toa-entry> </toa-div> </toa-div> <toa-div level="div1"> <title>securities act of 1933</title> <toa-div level="div2"> <title>rules</title> <toa-entry> <primary-entry id="s_sa_r_sa1933"> <entry-name>202(a)(30)-1(a)</entry-name> </primary-entry> </toa-entry> <toa-entry> <primary-entry id="s_sa_r_sa1933_1"> <entry-name>202(a)(30)-1(a)(1)</entry-name> </primary-entry> </toa-entry> </toa-div> </toa-div> </toa-section> <toa-section> <title>cases</title> <toa-div level="div1"> <title/> <toa-entry> <primary-entry id=">c_3mcovbrowner"> <entry-name>3m co. v. browner</entry-name> </primary-entry> </toa-entry> </toa-div> <toa-div level="div1"> <title>a</title> <toa-entry> <primary-entry id="c_abbatevus"> <entry-name>abbate v. united states</entry-name> </primary-entry> </toa-entry> <toa-entry> <primary-entry id="c_abelvus"> <entry-name>abel v. united states</entry-name> </primary-entry> </toa-entry> </toa-div> <toa-div level="div1"> <title>b</title> <toa-entry> <primary-entry> <entry-name>bacon v. comm’r</entry-name> </primary-entry> </toa-entry> <secondary-entry id="c_baconvcommr1"> <entry-name>september 1, 1982</entry-name> </secondary-entry> <secondary-entry id="c_baconvcommr2"> <entry-name>january 8, 1984</entry-name> </secondary-entry> <toa-entry> <primary-entry id="c_compaqcompvcommr"> <entry-name>compaq computer corp. v. comm’r</entry-name> </primary-entry> </toa-entry> </toa-div> </toa-section> </body> </toa>
please suggest me. in advance!
Comments
Post a Comment