2014-02-28 45 views
0

我在第三列的状态,但它的价值是在第一列来了...我该如何改变这种状况?如何更改XSLT中的列值?

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
    <html> 
     <body> 
<table border="1"> 
    <tr bgcolor="#9acd32"> 
    <th>Title</th> 
    <th>Artist</th> 
    <th>status</th> 
    </tr> 
    <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> 
    <tr> 
    <td><xsl:value-of select="title"/></td> 
    <td><xsl:value-of select="artist"/></td> 
    </tr> 
    </xsl:for-each> 
<xsl:for-each select="catalog/cd/dude" > 
    <tr> 
    <td><xsl:value-of select="status"/></td> 
    </tr> 
    </xsl:for-each> 
</table> 
</body> 
    </html> 
</xsl:template> 
    </xsl:stylesheet> 

基本上它的现身,如:

Title    Artist  status 
Empire Burlesque Bob Dylan 
hello 

我想:

Title    Artist  status 
Empire Burlesque Bob Dylan hello 

我如何去这样做呢?

这是源XML:

<catalog> 
    <cd> 
     <title>Empire Burlesque</title> 
     <artist>Bob Dylan</artist> 
     <country>USA</country> 
     <company>Columbia</company> 
     <price>10.90</price> 
     <year>1985</year> 
     <dude> 
      <status>hello</status> 
     </dude> 
    </cd> 
</catalog> 
+0

它看起来像你说你想你所得到的是同样的事情。即使在上面的评论中,似乎也是这样。 – RacerNerd

+0

<! - 编辑由XMLSpy的 - > \t \t \t 帝国滑稽 \t \t 鲍勃迪伦 \t \t 美国 \t \t 哥伦比亚 \t \t 10.90 \t \t \t 你好 \t user3362977

+0

你应该把你的代码示例中的问题。 – RacerNerd

回答

1

你是为status创建一个单独的行。既然你在一排有三列,你应该与其他两人一起添加dude列获得你的愿望:

<table border="1"> 
    <tr bgcolor="#9acd32"> 
     <th>Title</th> 
     <th>Artist</th> 
     <th>status</th> 
    </tr> 

    <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> 
     <tr> 
      <td><xsl:value-of select="title"/></td> 
      <td><xsl:value-of select="artist"/></td> 
      <td><xsl:value-of select="dude/status"/></td> 
     </tr> 
    </xsl:for-each> 
</table> 

这个迭代中包含artist子元素与文本Bod Dylan所有cd元素,当它发现一个,它增加了含有在你列3个<td>表格单元格<tr>表行。

你在做的方式在所有dude元素(只有一个)中迭代,并将status元素的内容放入新的<tr>行。这就是为什么你有一个额外的行。