2016-11-28 8 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> 

先頭、頭および頭は個別のグループである必要があります。どのようにグループ化することが可能か。

出力は以下のとおりです。

<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

あなたが何をしているか教えてくれない限り、間違っていることを教えてもらえません。 –

関連する問題