我需要使用 XSLT 将 xml 文件转换为 html 文件。现在我已经尝试了一切,但似乎没有用。我想在每个 alinea 之后创建一条白线。
XML代码:
<alinea>
Willen wij daadkrachtig het economisch herstel vorm kunnen geven, dan
is stabiel bestuur gewenst. Intensief wordt sinds de
<organisatie> Tweede Kamer</organisatie>
-verkiezingen van
<datum>9 juni</datum>
gewerkt aan de totstandkoming van een nieuw kabinet. Lopende de
kabinetsformatie past het huidige kabinet terughoudendheid bij het doen
van beleidsvoorstellen voor het komende jaar.
</alinea>
然后是很多 this 标签。
XSLT 代码:
<xsl:template match="troonrede">
<xsl:for-each select="troonrede/alinea">
<xsl:value-of select="troonrede/alinea"/><br/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>
我希望你能帮助我!
最佳答案
您还没有显示 troonrede
XML 中的元素,但假设它是 alinea
的父元素您的模板应如下所示...
<xsl:template match="troonrede">
<xsl:for-each select="alinea">
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</xsl:template>
这是因为在匹配 troonrede
的模板中然后您将定位在该元素上,因此您的 xsl:for-each
然后可以相对于当前节点。同样在 xsl:for-each
内,那么当前节点就是alinea
, 这样做 .
获取当前节点的值。 (执行 <xsl:value-of select="alinea"/>
会查找同一节点的子节点,该节点不存在。)
关于html - XSLT:for-each 循环只给出第一个 alinea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54061111/