inside title roman numbers as attribute values

时间:2017-06-20 12:31:25

标签: regex xml xslt

I want to add the tag inside value as num value and removing the section roman numbers and symbol inside the title tag

My Input XML File:

<?xml version="1.0" encoding="UTF-8"?>


<chapter id="d102e3" xml:lang="en-US">

<title outputclass="Chapter_Title">Base Food</title>
<subsection id="d102e11" xml:lang="en-US" outputclass="Heading_1">
<title> § I Nothing</title>
<body>
<p outputclass="Body_Text">1Y The Act also states that the may undertake a review of the definition of the term.</p>
</body>
</subsection>
<subsection id="d102e20" xml:lang="en-US" outputclass="Heading_2">
<title> § II Proposed Amendments: “Accredited Natural Person”</title>
<body>
</subsection>
<p outputclass="Body_Text">1Y The Act also states that the may undertake a review of the definition of the term.</p>
</body>
</chapter>

My XSLT Coding is

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


  <xsl:output method="xml" indent="yes" omit-xml-declaration="no"></xsl:output>



<xsl:template match="/">

  <xsl:apply-templates></xsl:apply-templates>
</xsl:template>


  <xsl:template match="*[contains(@class,' chapter/chapter ')]">
<chapter>
  <xsl:apply-templates/>
</chapter>
  </xsl:template>

  <xsl:template match="subsection">
<section level="sect{format-number(count(preceding::subsection)+1,'0000')}" num="I" number-type="manual">
  <xsl:apply-templates/>
</section>
  </xsl:template>

  <xsl:template match="*[contains(@class,' topic/p ')]">
<para>
   <xsl:apply-templates/>
</para>
  </xsl:template>

  <xsl:template match="*[contains(@class,' topic/title ')]">
<title>
  <xsl:apply-templates/>
</title>
   </xsl:template>
  </xsl:stylesheet>


</xsl:stylesheet>

I am getting output as

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<chapter>

<title>Base Food</title>
<section level="sect0001" num="I" number-type="manual">
<title> § I Nothing</title>
<para>1Y The Act also states that the may undertake a review of the definition of the term.</para>
</section>
<section level="sect0001" num="I" number-type="manual">
<title> § II Proposed Amendments: “Accredited Natural Person”</title>
<para>1Y The Act also states that the may undertake a review of the definition of the term.</para>
</section>

</chapter>

but i want output in side title tag roman number format in 'num' attributes and remove the number and symbol '§ I' inside title tag:

output needed as

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<chapter>
<title>Base Food</title>
<section level="sect1" num="&#x00A7;&#x00A0;I" number-type="manual">
<title>Nothing</title>
<para>1Y The Act also states that the may undertake a review of the definition of the term.</para>
</section>
<section level="sect2" num="&#x00A7;&#x00A0;II" number-type="manual">
<title>Proposed Amendments: “Accredited Natural Person”</title>
<para>1Y The Act also states that the may undertake a review of the definition of the term.</para>
</section>
</chapter>

Please assist me.

Thanks in Advance

0 个答案:

没有答案