2016-10-06 2 views
1

Я все еще новичок в xslt.I имею проблемы, прокладывая строки и столбцы.Xslt повторить строку после двух узлов (бутстрап)

Я получил XML-как это ::

<Section Elem="Overview" child="4.0"> 
    <Section Elem="View 1" child="2.0"> 
    <Doc Elem="Tab 1"> 
    <Tit Elem="Code">Tit 1</Tit> 
    <Descr Elem="Descr1">Descr 1 </Descr> 
    </Doc> 
    </Section> 
    <Section Elem="View 2" child="2.0"> 
    <Doc Elem="Tab 2"> 
    <Tit Elem="Code">Tit 2</Tit> 
    <Descr Elem="Descr2">Descr 2 </Descr> 
    </Doc> 
    </Section>    
    <Section Elem="View 3" child="0.0"> 
    <Doc Elem="Tab 3"> 
    <Tit Elem="Code">Tit 3</Tit> 
    <Descr Elem="Descr3">Descr 3 </Descr> 
    </Doc> 
    </Section> 
    <Section Elem="View 4" child="0.0"> 
    <Doc Elem="Tab 4"> 
    <Tit Elem="Code">Tit 4</Tit> 
    <Descr Elem="Descr3">Descr 4 </Descr> 
    </Doc> 
    </Section> 
</Section> 

Желаемый результат:

<div class="row"> 
    <div class="col-md-6"> 
     <h2>Tit 1</h2> 
    </div> 
    <div class="col-md-6"> 
     <h2>Tit 2</h2> 
    </div> 
</div> 
<div class="row"> 
<div class="col-md-6"> 
    <h2>Tit 3</h2> 
    </div> 
    <div class="col-md-6"> 
    <h2>Tit 4</h2> 
    </div> 
</div> 

Я попробовал несколько вещей (на основе поиска в ответах на StackOverflow), но ни один из них не дает мне желаемый выпуск. нравится:

<xsl:template match="/"> 

<xsl:template match="Section/Section[position() mod 2 =1]"> 
    <div class="row"> 
     <xsl:apply-templates mode="proc" select=".|following- sibling::Section[not(position() > 2)]" /> 
    </div> 
    </xsl:template> 

<xsl:template match="Section" mode="proc"> 
     <div class="col-md-6">  
    <h2> <xsl:value-of select="Tit"/></h2> 
     </div> 
</xsl:template> 

    <xsl:template match="Section[not(position() mod 2 = 1)]"/> 

или что тоже не работает:

<xsl:param name="pNumCols" select="3"/> 
    <xsl:template match="/"> 
<xsl:apply-templates select="/Sectie[position() mod $columns = 1]"/> 
    </xsl:template> 

    <xsl:template match="/Section">  <div class="row"> 
    <div class="col-md-6"> 
<xsl:for-each select=".|following-sibling::Section[not(position() > $pNumCols -1)]">   <h2> <xsl:value-of select="Tit"/></h2> 
</xsl:for-each>  </div> 
</div> 
</xsl:template> 

Моя самая большая проблема в том, что я не могу повторить после двух секций частей.

+0

Так почему бы помечено этот вопрос [теги: CSS]? – connexo

ответ

0

После XSLT 1.0 таблица стилей

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="html"/> 

    <xsl:template match="/Section"> 
     <removeable> 
      <xsl:apply-templates select="Section[position() mod 2 = 1]"/> 
     </removeable> 
    </xsl:template> 

    <xsl:template match="Section"> 
     <div class="row"> 
      <xsl:apply-templates select=". | following-sibling::Section[1]" mode="proc"/> 
     </div> 
    </xsl:template> 

    <xsl:template match="Section" mode="proc"> 
     <div class="col-md-6"> 
      <h2> 
       <xsl:value-of select="Doc/Tit"/> 
      </h2> 
     </div> 
    </xsl:template> 

</xsl:stylesheet> 

Результаты в

<removeable> 
    <div class="row"> 
    <div class="col-md-6"> 
     <h2>Tit 1</h2> 
    </div> 
    <div class="col-md-6"> 
     <h2>Tit 2</h2> 
    </div> 
    </div> 
    <div class="row"> 
    <div class="col-md-6"> 
     <h2>Tit 3</h2> 
    </div> 
    <div class="col-md-6"> 
     <h2>Tit 4</h2> 
    </div> 
    </div> 
</removeable> 
Смежные вопросы