本文发表在 rolia.net 枫下论坛and i have only IE5.5, which does not allow me to try some new functions(if, variable), so my codes are very very un-professional, please dont laugh at me. See if it helps or not
xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
<entry>111</entry>
<entry b="1">222</entry>
<entry href="google">333</entry>
<entry href="yahoo" b="1">444</entry>
<entry></entry>
</root>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<table border="1">
<xsl:for-each select="root/entry">
<tr>
<td>
<xsl:choose>
<xsl:when test=".[@b='1']">
<b>
<xsl:choose>
<xsl:when test="@href">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</b>
</xsl:when>
<xsl:when test="@href">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:when>
<xsl:when test=".[.='']">
N/A
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>更多精彩文章及讨论,请光临枫下论坛 rolia.net
xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
<entry>111</entry>
<entry b="1">222</entry>
<entry href="google">333</entry>
<entry href="yahoo" b="1">444</entry>
<entry></entry>
</root>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<table border="1">
<xsl:for-each select="root/entry">
<tr>
<td>
<xsl:choose>
<xsl:when test=".[@b='1']">
<b>
<xsl:choose>
<xsl:when test="@href">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</b>
</xsl:when>
<xsl:when test="@href">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:when>
<xsl:when test=".[.='']">
N/A
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>更多精彩文章及讨论,请光临枫下论坛 rolia.net