[英]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.