xsl-list
[Top] [All Lists]

Re: [xsl] ID Generation for XML Element

2010-10-29 05:52:11
Ramkumar.V wrote:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"> <xsl:output method="xml" encoding="us-ascii" indent="no" omit-xml-declaration="no" include-content-type="no" /> <xsl:template match="root"><article><xsl:apply-templates/></article></xsl:template> <xsl:template match="sect"><section id="sec{position() div 2}"><xsl:apply-templates/></section></xsl:template> <xsl:template match="sect/title"><title><xsl:apply-templates/></title></xsl:template> <xsl:template match="para"><p><xsl:apply-templates/></p></xsl:template> </xsl:stylesheet>

<?xml version="1.0" encoding="us-ascii"?><article>
   <section id="sec1">
       <title>Section Head1</title>
       <p>Paragraph text</p>
   </section>
<p>Element para or some other any element and any no.of element may come here</p>
   <section id="sec2">

Try it with xsl:number
  <xsl:template match="sect">
    <xsl:variable name="pos"><xsl:number/></xsl:variable>
    <section id="sec{$pos}">
      <xsl:apply-templates/>
    </section>
  </xsl:template>


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--