本例的xsl中,该怎么实现集合或,与的操作呢
本例的xsl中,该如何实现集合或,与的操作呢?
WORKERS.XML文件如下:
<?xml version= "1.0 " encoding= "gb2312 "?>
<?xml-stylesheet type= "text/xsl " href= "Workers.xsl "?>
<WORKERS>
<WORKER ID= "1 ">
<name> BUSH </name>
<salary> 1000 </salary>
</WORKER>
<WORKER ID= "2 ">
<name> ROBIN </name>
<salary> 2000 </salary>
</WORKER>
<WORKER ID= "3 ">
<salary> 3000 </salary>
</WORKER>
</WORKERS>
相应的WORKERS.XSL文件如下:
<?xml version= "1.0 " encoding= "gb2312 " ?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " version= "1.0 ">
<xsl:template match= "WORKERS ">
<table align= "center " border= "1 ">
<xsl:apply-templates select= "WORKER[*[@ID= '2 '] | WORKER[not$name] " />
</table>
</xsl:template>
<xsl:template match= "WORKER[*[@ID= '2 '] | WORKER[not$name] ">
<xsl:for-each select= ". ">
<tr>
<td> 工资 </td>
<td> <xsl:value-of select= "salary " /> </td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
本例子想达到的目的是: 输出满足条件“ID= '2 ',或者WORKER下面没有name子元素”的WORKER元素的salary,不知道该怎样写?集合操作不会用啊(当然,此例中,判断不存在name子元素的方法也不对,因为不知道如何写的)?
另外,如果想实现“与”操作,似乎不能用 <xsl:apply-templates select= "WORKER[*[@ID= '2 '] and WORKER[not$name] " /> 的形式,那样该如何写呢?
非常谢谢大家啊.
------解决方案--------------------
<?xml version= "1.0 " encoding= "gb2312 " ?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " version= "1.0 ">
<xsl:template match= "WORKERS ">
<table align= "center " border= "1 ">
<xsl:apply-templates select= "WORKER[@ID= '2 ' or not(name)] " />
</table>
</xsl:template>
<xsl:template match= "WORKER ">
<xsl:for-each select= ". ">
<tr>
<td> 工资 </td>
<td> <xsl:value-of select= "salary " /> </td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
WORKERS.XML文件如下:
<?xml version= "1.0 " encoding= "gb2312 "?>
<?xml-stylesheet type= "text/xsl " href= "Workers.xsl "?>
<WORKERS>
<WORKER ID= "1 ">
<name> BUSH </name>
<salary> 1000 </salary>
</WORKER>
<WORKER ID= "2 ">
<name> ROBIN </name>
<salary> 2000 </salary>
</WORKER>
<WORKER ID= "3 ">
<salary> 3000 </salary>
</WORKER>
</WORKERS>
相应的WORKERS.XSL文件如下:
<?xml version= "1.0 " encoding= "gb2312 " ?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " version= "1.0 ">
<xsl:template match= "WORKERS ">
<table align= "center " border= "1 ">
<xsl:apply-templates select= "WORKER[*[@ID= '2 '] | WORKER[not$name] " />
</table>
</xsl:template>
<xsl:template match= "WORKER[*[@ID= '2 '] | WORKER[not$name] ">
<xsl:for-each select= ". ">
<tr>
<td> 工资 </td>
<td> <xsl:value-of select= "salary " /> </td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
本例子想达到的目的是: 输出满足条件“ID= '2 ',或者WORKER下面没有name子元素”的WORKER元素的salary,不知道该怎样写?集合操作不会用啊(当然,此例中,判断不存在name子元素的方法也不对,因为不知道如何写的)?
另外,如果想实现“与”操作,似乎不能用 <xsl:apply-templates select= "WORKER[*[@ID= '2 '] and WORKER[not$name] " /> 的形式,那样该如何写呢?
非常谢谢大家啊.
------解决方案--------------------
<?xml version= "1.0 " encoding= "gb2312 " ?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " version= "1.0 ">
<xsl:template match= "WORKERS ">
<table align= "center " border= "1 ">
<xsl:apply-templates select= "WORKER[@ID= '2 ' or not(name)] " />
</table>
</xsl:template>
<xsl:template match= "WORKER ">
<xsl:for-each select= ". ">
<tr>
<td> 工资 </td>
<td> <xsl:value-of select= "salary " /> </td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>