Thanks Michael. It's working fine for me.
Thanks
Srinivasan
-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Sent: Thursday, August 06, 2009 3:05 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] selecting a section element which parent element doesn't
have any element other than title element
Something like this:
<!-- Rule for a Type 1 section -->
<xsl:template match="section">
<xsl:copy>
<xsl:attribute name="role">
<xsl:text>H</xsl:text>
<xsl:value-of select="count(ancestor::section)+1"/>
</xsl:attribute>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- Rule for a Type 2 section -->
<xsl:template match="section[not(preceding-sibling::*[not(self::title)]]">
<xsl:copy>
<xsl:attribute name="role">
<xsl:for-each select="reverse(1 to count(ancestor::section)+1)"/>
<xsl:text>H</xsl:text>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:attribute>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
-----Original Message-----
From: srinivasan(_dot_)p(_at_)textech(_dot_)in
[mailto:srinivasan(_dot_)p(_at_)textech(_dot_)in]
Sent: 06 August 2009 10:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] selecting a section element which parent
element doesn't have any element other than title element
Hi Team,
I need the following output from the following input. In the following
Input1 example, "..." means any opening and closing tag can
be present.
Input1:
<book>
<section>
<title>Section 1 title Present here</title> ...
<section>
<title>Section 2 title present here</title> </section>
</section> </book>
Output1:
<book>
<section role="H1">
<title>Section 1 title Present here</title> ...
<section role="H2">
<title>Section 2 title present here</title> </section>
</section> </book>
Input2:
<book>
<section>
<title>Section 1 title Present here</title> <section>
<title>Section 2 title present here</title> </section>
</section> </book>
Output2:
<book>
<section role="H1">
<title>Section 1 title Present here</title> <section
role="H2H1"> <title>Section 2 title present here</title>
</section> </section> </book>
I am using the same style sheet to achieve these two outputs.
I don?t have any issues in achieving output1. The problem is
in output2. I need to select the "section" element which
parent is "section" that doesn't contain any tags other than
"title" element.
Can you please anyone suggest to me how to achieve this in XSLT 2.0?
Thanks in advance.
Thanks
Srinivasan
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--