之前,我有这样的XML获取一些元素项目的值与条件
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="do.xsl"?>
<catalog>
<cd>
<title_>Empire Burlesque</title_>
<artist>Bobby</artist>
<company>Columbia</company>
</cd>
<cd>
<title_>Shirt2</title_>
<artist>Bobby</artist>
<company>Columbia2</company>
</cd>
<cd>
<title_>Fingers</title_>
<artist>Bobby</artist>
<company>Columbia3</company>
</cd>
<cd>
<title_>Zip1</title_>
<artist>Bobby</artist>
<company>---</company>
</cd>
<cd>
<title_>Zip2</title_>
<artist>Bobby</artist>
<company>---</company>
</cd>
</catalog>
我需要更换---与以前的有意义的数据 - Columbia3 我接下来做
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="utf-8" indent="yes"/>
<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>
<td>
<xsl:variable name="NotStarted" select="preceding-sibling::cd[1]/company" />
<xsl:choose>
<xsl:when test="company != '---'">
<xsl:value-of select="company"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$NotStarted" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
正如预期的那样我得到了下一个HTML
Title Artist
Empire Burlesque Bobby Columbia
Shirt2 Bobby Columbia2
Fingers Bobby Columbia3
Zip1 Bobby Columbia3
Zip2 Bobby ---
我如何迭代得到最后有意义的字符串替换或任何o其他方式?谢谢。
定义“有意义”。 – 2012-07-18 12:26:54
@Dimitre Novatchev,我想这里很清楚,不需要额外的解释。我也认为你太过于苛刻了)) – Yola 2012-07-18 13:48:22
一点也不 - 你至少可以提供确切的想要的结果 - 如果即使缺少这个结果,人们也可以将“有意义”定义为字符串“”有意义的“,并给你这个:'有意义的 ' –
2012-07-18 14:30:37