2016-11-28 40 views
-1

我有以下过程的HTML。如何按XSL中的元素进行分组

<p class="Ahead">FIRST SECTION</p> 
    <p class="Text">with a moisture content of 16.34</p> 
    <p class="Ahead">SECOND SECTION</p> 
    <p class="Bhead">Second First Section</p> 
     <p class="Text">with a moisture content of 20.56</p> 
     <p class="Chead">Second first first section</p> 
     <p class="Text">with a moisture content of 48.15</p> 

未来,Bhead和Chead应该是个体小组。它如何分组。

输出应该如下。

<sec> 
    <title>FIRST SECTION</title> 
    <p class="Text">with a moisture content of 16.34</p> 
</sec> 
<sec> 
    <title>SECOND SECTION</title> 
    <sec 
    <title>Second First Section</title> 
    <p class="Text">with a moisture content of 20.56</p> 
    <sec> 
     <title>Second first first section</title> 
     <p class="Text">with a moisture content of 48.15</p> 
    </sec> 
    </sec> 
</sec> 

在此先感谢。

回答

0

事情是这样的:

<xsl:function name="f:group"> 
    <xsl:param name="level" as="xs:integer"/> 
    <xsl:param name="population" as="element()*"/> 
    <xsl:variable name="name" select="('Ahead', 'Bhead', 'Chead')[$level]"/> 
    <xsl:for-each-group select="$population" 
    group-starting-with="p[@class=$name]"> 
    <xsl:choose> 
     <xsl:when test="@class='Text'"> 
     <xsl:copy-of select="current-group()"/> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:sequence select="f:group($level+1, current-group())"/> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:for-each-group> 
</xsl:function> 

则:

<xsl:template match="/"> 
    <xsl:sequence select="f:group(1, //p)"/> 
</xsl:template> 

没有测试,只是一些对你下手。

+0

我不能告诉你你做错了什么,除非你告诉我你在做什么。 –

相关问题