在 xslt 中添加新行
Add a new line in xslt
如何在 XSLT 中添加一个新行,我已经尝试过 <xsl:text>
</xsl:text>
但它没有用,我也试过 <xsl:text></xsl:text>
它也不是每次都有效。没有其他解决方案吗?
xml:
<composition>
<ion type="positif">calcium 67.32mg/l</ion>
<ion type="positif">magnésium 10.08mg/l</ion>
<ion type="negatif">chlorure 20.82mg/l</ion>
<ion type="negatif">nitrate 3.5mg/l</ion>
<autre type="metal">fer</autre>
</composition>
xslt:
<tr>
<xsl:for-each select="./bouteille/composition" >
<td>
<xsl:value-of select="./ion[@type='negatif']"/><xsl:text> <!-- Won't add a new line -->
</xsl:text>
</td>
</xsl:for-each>
</tr>
您发布的示例不完整。不过,它明确指出的一件事是您正在生成 HTML table。因此,您应该使用 <br/>
在 table 单元格中创建新行。
可能是这样的:
<td>
<xsl:for-each select="ion[@type='negatif']"/>
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</td>
没有上下文可以借鉴,恐怕不能更准确了。
如何在 XSLT 中添加一个新行,我已经尝试过 <xsl:text>
</xsl:text>
但它没有用,我也试过 <xsl:text></xsl:text>
它也不是每次都有效。没有其他解决方案吗?
xml:
<composition>
<ion type="positif">calcium 67.32mg/l</ion>
<ion type="positif">magnésium 10.08mg/l</ion>
<ion type="negatif">chlorure 20.82mg/l</ion>
<ion type="negatif">nitrate 3.5mg/l</ion>
<autre type="metal">fer</autre>
</composition>
xslt:
<tr>
<xsl:for-each select="./bouteille/composition" >
<td>
<xsl:value-of select="./ion[@type='negatif']"/><xsl:text> <!-- Won't add a new line -->
</xsl:text>
</td>
</xsl:for-each>
</tr>
您发布的示例不完整。不过,它明确指出的一件事是您正在生成 HTML table。因此,您应该使用 <br/>
在 table 单元格中创建新行。
可能是这样的:
<td>
<xsl:for-each select="ion[@type='negatif']"/>
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</td>
没有上下文可以借鉴,恐怕不能更准确了。