在编写XSLT时需要帮助 [英] need help in writing XSLT

查看:57
本文介绍了在编写XSLT时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我试图将XML文档转换为HTML。并试图为此编写一个XSLT文件。我可以在这种情况下得到帮助..

如果xml如下:

hi all.
i m trying to transforming a XML doc into a HTML. and trying to write a XSLT file for this. may i got help in this scenario..
if xml is like:

<catalog>
	<cd>
		<title>Empire Burlesque</title>
		<artist>Bob Dylan</artist>
		<country>USA</country>
		
	</cd>
</catalog>





xslt woulb是这样的:



the xslt woulb be like this:

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>





但是如果xml是这样的:



but if xml is like this:

<catalog>
	<cd>
		<title name="Empire Burlesqu"/>
		<artist name="Bob Dylan"/>
		<country name="USA"/>
		
	</cd>
</catalog>





XSLT怎么样?对于这个。



how would be the XSLT for this.

推荐答案

尝试这个,它应该工作



Try this, it should work

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title/@name"/></td>
        <td><xsl:value-of select="artist/@name"/></td>
        <td><xsl:value-of select="country/@name"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>


这篇关于在编写XSLT时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆