xslt to rename nodes based on recursive position

IgorDudekBL

New Member
I am attempting to travel through the nodes in my XHTML document, finding all the node children, and renaming them based on the position of the descendant in the doc. For example:I want to iterate over the nodes in the element, test if they have a name of H2 and output them as h3, with all their attributes intact, and outputting their content intact.Then I want to iterate over all the other children of the element, and find their child nodes, with a name of greater than h3, and names these to h4, and etc, up to unlimited depth, but up to a limit of h6...is this clear? Pardon, I am new to xsl. Here is what I have so far:\[code\]<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy></xsl:template><xsl:template match="*[contains(@class,'_col')]"> <xsl:apply-templates select="*" mode="iterate"/></xsl:template><xsl:template match="*" mode="iterate"> <xsl:if test="name()='h1' or name()='h2'or name()='h3'or name()='h4'or name()='h5'or name()='h6'"> <h6> <xsl:apply-templates select="@*|node()"/> </h6> </xsl:if> <xsl:if test="name()!='h1' and name()!='h2' and name()!='h3' and name()!='h4' and name()!='h5' and name()!='h6'"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:if></xsl:template>\[/code\]Obviously this won't work at all - leaving off the increment of the h# tag, if I can simply get the sheet to output the complete document with all the h# tags transormed to h1 tags, I'd feel pretty good. Can anyone help out?thanks.
 
Back
Top