how to find the find the following scenario in XSLT



I have content like this:



<sect1>
<title>Leiblichkeit und Verk&#x00F6;rperung</title>
<sect2>
<title>Leiblichkeit und Verk&#x00F6;rperung</title>
<para>
.......
</para>
</sect2>
<sect2>
<title>Leiblichkeit und Verk&#x00F6;rperung</title>
<para>
.......
</para>
</sect2>
</sect1>


I want to match and apply attribute for sect2's title if its continues to sect1 as "below_2_head"


I tried:



<xsl:template match="title">
<xsl:copy>
<xsl:if test="parent::sect1"><xsl:attribute name="aid:pstyle">1_head</xsl:attribute></xsl:if>
<xsl:if test="parent::sect2"><xsl:attribute name="aid:pstyle"><xsl:if test="parent::sect2/preceding-sibling::title">below_</xsl:if>2_head</xsl:attribute></xsl:if>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>


I want the output as:



<sect1>
<title aid:pstyle="1_head">Leiblichkeit und Verk&#x00F6;rperung</title>
<sect2>
<title aid:pstyle="below_2_head">Leiblichkeit und Verk&#x00F6;rperung</title>
<para>
.......
</para>
</sect2>
<sect2>
<title aid:pstyle="2_head">Leiblichkeit und Verk&#x00F6;rperung</title>
<para>
.......
</para>
</sect2>
</sect1>

No comments:

Post a Comment