<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<Company_Y>
<Branch>
<branchNo>11</branchNo><street>163 Main street</street><city>abc</city><postcode>111</postcode>
</Branch>
<Staff>
<staffNo>11</staffNo><Name>abhishek</Name><position>asd</position><sex>m</sex><DOB>01-Feb-1991</DOB><salary>122</salary><branchNo>11</branchNo>
</Staff>
<PropertyforRent>
<propertyNo>11</propertyNo><street>163 Main street</street><city>abc</city><postcode>111</postcode><type>a</type><rooms>3</rooms><rent>334</rent><ownerNo>23</ownerNo><staffNo>11</staffNo><branchNo>11</branchNo>
</PropertyforRent>
<Client>
<clientNo>22</clientNo><Name>dsf</Name><telNo>33</telNo><prefType>gdf</prefType><maxRent>343</maxRent>
</Client>
<PrivateOwner>
<ownerNo>23</ownerNo><Name>dsfd</Name><address>dfsd</address><telNo>3423</telNo>
</PrivateOwner>
<Viewing>
<clientNo>23</clientNo><propertyNo>dfg</propertyNo><viewDate>01-Feb-1991</viewDate><comment>dgfsdsd</comment>
</Viewing>
<Registration>
<clientNo>34</clientNo><branchNo>11</branchNo><staffNo>11</staffNo><dateJoined>01-Feb-1991</dateJoined>
</Registration>
</Company_Y>
这是我用来创建xml文件的内容
分支(branchNo,街道,城市,邮政编码)
工作人员(工作人员没有,姓名,职位,性别,DOB,工资,分支机构没有)
PropertyforRent(propertyNo,street,city,postcode,type,rooms,rent,ownerNo,staffNo, branchNo)
客户端(clientNo,Name,telNo,prefType,maxRent)
PrivateOwner(ownerNo,Name,address,telNo)
查看(clientNo,propertyNo,viewDate,comment)
注册(clientNo,branchNo,staffNo,dateJoined)
我必须为此写xslt 列出在街道地址为“163 Main street”的分行工作的员工姓名。
我写的是这个,它不起作用。 PLZ帮忙??
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>List the name of staff who work in the branch whose street address is ‘163 Main street’</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>name</th>
<th>street</th>
</tr>
<xsl:for-each select="Company_Y/Branch">
<xsl:if test="street='163 Main street'">
p=value-of select="branchNo"
<xsl:for-each select="Company_Y/Staff">
<xsl:if test1="branchNo=p">
<tr>
<td><xsl:value-of select="branchNo"/></td>
<td><xsl:value-of select="Name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
您可以将目标branchNo分配给xsl变量并在for-each循环中使用它
<xsl:variable name="branch" select="Company_Y/Branch[street='163 Main street']/branchNo" />
<xsl:for-each select="Company_Y/Staff[branchNo=$branch]">
<tr bgcolor="#9acd32">
<td><xsl:value-of select="branchNo"/></td>
<th><xsl:value-of select="Name" /></th>
</tr>
</xsl:for-each>