2016-03-24 69 views
0

我非常喜欢XSLT,我想根据XML文件中的特定属性将XML文件拆分为多个HTML文件。将XSLT拆分为多个HTML文件

这里是我的XML文件的样本:

<article> 
<div> 
<paragraph>text text text</paragraph> 
</div> 
<div class="zoologie"> 
<def>this is a definition</def> 
<def>this is another definition</def> 
<example>this is a first example</example> 
<example>this is a second example</example> 
</div> 
</article> 

<article> 
<div> 
<paragraph>text text text</paragraph> 
</div> 
<div class="médecine"> 
<def>this is a definition</def> 
<def>this is another definition</def> 
<example>this is a first example</example> 
<example>this is a second example</example> 
</div> 
</article> 

<article> 
<div> 
<paragraph>text text text</paragraph> 
</div> 
<div class="zoologie"> 
<def>this is a definition</def> 
<def>this is another definition</def> 
<example>this is a first example</example> 
<example>this is a second example</example> 
</div> 
</article> 

我想获得一个HTML文件组togheter具有相同属性类的所有文章。例如,一个名为zoologie.html的HTML文件收集包含属性class =“zoologie”的所有文章。另一个名为médecine.html的HTML文件收集了属性class =“médecine”的所有文章。我已经尝试了分割功能,但它不会工作。如果你能帮助我,我会很感激。 谢谢, 弗洛

+0

您可以使用XSLT 2.0处理器和'xsl:result-document',还是使用支持扩展的XSLT 1.0处理器来创建具有一个样式表的多个文档? –

+0

我可以使用XSLT 2.0处理器 – FloD

回答

0

这是一个典型的XSLT 2.0构造:

<xsl:for-each-group select="article" group-by="div/@class"> 
    <xsl:result-document href="{current-grouping-key()}.xml"> 
    <articles> 
     <xsl:copy-of select="current-group()"/> 
    </articles> 
    </xsl:result-document> 
</xsl:for-each-group> 

XSLT 1.0没有任何内建做分组或产生多个输出文件的能力,但一些1.0的处理器可能有供应商扩展帮助。

+0

谢谢您的回答。它实际上并没有工作。我不知道为什么。对于我的目标,我不得不使用另一种方法,即选择另一个具有我想要的值的属性。然后我可以为每个文件生成一个HTML文件。我有一个会议的最后期限,我不能再想一想使用分割功能的方法。再次感谢。 – FloD