简体   繁体   English

从XML在XSLT中显示idref

[英]Display idref in XSLT from XML

I'm trying to display the information within the idref quotations in a table this is how it is displayed in my 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>

So far I have gotten the tabel to display the other elements. 到目前为止,我已经获得了显示其他元素的表格。 Here is my XSL code. 这是我的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>

When I do this the columns for capital and cities are blank. 当我这样做时,首都和城市的列为空白。 Also, since there are multiple elements each with a attribute. 同样,由于存在多个具有属性的元素。 How would I display each of thos attributes? 我将如何显示每个thos属性? Any help would be appreciated. 任何帮助,将不胜感激。 Thank you. 谢谢。

capital and citiesin are the elements in your input, but the value you want to output is in their idref attribute , so you must use: capitalcitiesin是输入中的元素 ,但是要输出的值在其idref 属性中 ,因此必须使用:

<td><xsl:value-of select="capital/@idref" /></td>
<td><xsl:value-of select="citiesin/@idref" /></td>

In order to display all the citiesin/@idref values while using XSLT 1.0 you have to use a for-each loop: 为了在使用XSLT 1.0时显示所有citiesin/@idref值,必须使用for-each循环:

<td>
    <xsl:for-each select="capital">
        <xsl:value-of select="@idref"/>
    </xsl:for-each>
</td>

With XSLT 2.0 this is not necessary, as <xsl:value-of select="citiesin/@idref" /> will already return a sequence containing all the values. 在XSLT 2.0中,这不是必需的,因为<xsl:value-of select="citiesin/@idref" />将已经返回包含所有值的序列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM