[英]Display idref in XSLT from XML
我试图在表的idref引号中显示信息,这就是它在XML中的显示方式。
<state id="illinois">
<scode>IL</scode>
<sname>Illinois</sname>
<capital idref="springfieldi"/>
<citiesin idref="springfieldi"/>
<citiesin idref="bloomington"/>
<citiesin idref="chicago"/>
<citiesin idref="peoria"/>
<nickname>Prairie State</nickname>
<population>12128370</population>
</state>
到目前为止,我已经获得了显示其他元素的表格。 这是我的XSL代码。
<table border="2">
<tr bgcolor="grey">
<th style="width:40px">ID</th>
<th>Name</th>
<th>Capital</th>
<th>Cities</th>
<th>Nickname</th>
<th>Population</th>
</tr>
<xsl:for-each select="geography/state">
<tr>
<td><xsl:value-of select="scode" /></td>
<td><xsl:value-of select="sname" /></td>
<td><xsl:value-of select="capital" /></td>
<td><xsl:value-of select="citiesin" /></td>
<td><xsl:value-of select="nickname" /></td>
<td><xsl:value-of select="population" /></td>
</tr>
</xsl:for-each>
</table>
当我这样做时,首都和城市的列为空白。 同样,由于存在多个具有属性的元素。 我将如何显示每个thos属性? 任何帮助,将不胜感激。 谢谢。
capital
和citiesin
是输入中的元素 ,但是要输出的值在其idref
属性中 ,因此必须使用:
<td><xsl:value-of select="capital/@idref" /></td>
<td><xsl:value-of select="citiesin/@idref" /></td>
为了在使用XSLT 1.0时显示所有citiesin/@idref
值,必须使用for-each
循环:
<td>
<xsl:for-each select="capital">
<xsl:value-of select="@idref"/>
</xsl:for-each>
</td>
在XSLT 2.0中,这不是必需的,因为<xsl:value-of select="citiesin/@idref" />
将已经返回包含所有值的序列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.