I have a complete docbook xml file there are nested <section> elements, I want to split xml base on the <section> tag, Could you please support to sort out this concern for your reference here with attached input sample and required output. Thanks in advance
Input File:
<?xml version="1.0" encoding="UTF-8"?>
<section id="audit">
<sectioninfo>
<titleabbrev>Abbrev title here</titleabbrev>
<title>I am title</title>
</sectioninfo>
<para>Content here</para>
<para>content here</para>
<section id="introduction">
<sectioninfo>
<titleabbrev>Introduction</titleabbrev>
<title>Introduction</title>
</sectioninfo>
<section id="aag_1">
<sectioninfo>
<titleabbrev>1.01</titleabbrev>
<title>1.01</title>
</sectioninfo>
<para>Content here</para>
</section>
<section id="aag_2">
<sectioninfo>
<titleabbrev>1.02</titleabbrev>
<title>1.02</title>
</sectioninfo>
<para>Content here</para>
</section>
</section>
</section>
Required Output File:
section_audit.xml
<section id="audit">
<sectioninfo>
<titleabbrev>Abbrev title here</titleabbrev>
<title>I am title</title>
</sectioninfo>
<para>Content here</para>
<para>content here</para>
</section>
section_introduction.xml
<section id="introduction">
<sectioninfo>
<titleabbrev>Introduction</titleabbrev>
<title>Introduction</title>
</sectioninfo>
</section>
section_aag_1.xml
<section id="aag_1">
<sectioninfo>
<titleabbrev>1.01</titleabbrev>
<title>1.01</title>
</sectioninfo>
<para>Content here</para>
</section>
section_aag_2.xml
<section id="aag_2">
<sectioninfo>
<titleabbrev>1.02</titleabbrev>
<title>1.02</title>
</sectioninfo>
<para>Content here</para>
</section>
XSL File:
<xsl:for-each select="chapter/section">
<xsl:variable name="output" select="concat(@id, '.xml')"/>
<xsl:result-document href="{concat('section_', $output)}" method="xml" encoding="utf-8">
<book>
<xsl:if test="@id">
<xsl:attribute name="id" select="@id"/>
</xsl:if>
<xsl:copy-of select="ancestor::book/bookinfo" copy-namespaces="no"/>
<section>
<xsl:if test="@id">
<xsl:attribute name="id" select="@id"/>
</xsl:if>
<xsl:copy-of select="." copy-namespaces="no"/>
</section>
</book>
</xsl:result-document>
</xsl:for-each>