-- 作者:98900969r
-- 发布时间:12/12/2005 2:39:00 PM
--
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xh="http://www.w3.org/1999/xhtml"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="@* | text() | processing-instruction() | comment()"> <xsl:copy/> </xsl:template> <xsl:template match="text() [parent::xh:h1 or parent::xh:h2 or parent::xh:h3 or parent::xh:h4 or parent::xh:h5 or parent::xh:h6]"> <xsl:for-each select="parent::*"> <xsl:variable name="n0" select="number( substring-after(local-name(.), 'h') )"/> <xsl:variable name="n" select="$n0"/> <xsl:call-template name="hn"> <xsl:with-param name="n0" select="$n0"/> <xsl:with-param name="n" select="$n"/> <xsl:with-param name="s0" select="''"/> </xsl:call-template> </xsl:for-each> <xsl:apply-templates/> </xsl:template> <xsl:template name="hn"> <xsl:param name="n0"/> <xsl:param name="n"/> <xsl:param name="s0"/> <xsl:choose> <xsl:when test="$n>=1"> <xsl:variable name="hp"> <xsl:variable name="hn_1_t" select="string(preceding-sibling::* [local-name(.)=concat('h', number($n)-1)] [last()])"/> <xsl:choose> <xsl:when test="$n=1"> <xsl:choose> <xsl:when test="$n!=$n0"> <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n)])"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n)] )+1"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$n!=$n0"> <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n) and preceding-sibling::* [local-name(.)=concat('h', number($n)-1) and .=$hn_1_t ] ] )"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n) and preceding-sibling::* [local-name(.)=concat('h', number($n)-1) and .=$hn_1_t ] ] )+1"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="s"> <xsl:choose> <xsl:when test="$n=$n0"> <xsl:value-of select="concat($s0, $hp, ' ', .)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat($hp, '.', $s0 )"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:call-template name="hn"> <xsl:with-param name="n0" select="$n0"/> <xsl:with-param name="n" select="number($n)-1"/> <xsl:with-param name="s0" select="$s"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$s0"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> [此贴子已经被作者于2005-12-12 19:22:22编辑过]
|