这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="coursestyle.xsl"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ns0:FindCoursesForOffenderResponse xmlns:ns0="http://H.FindCoursesForOffenderResponse">
<ns0:SiteList>
<ns0:SiteEntity>
<ns0:SiteId>10</ns0:SiteId>
<ns0:SiteName>Ramada Watford</ns0:SiteName>
</ns0:SiteEntity>
<ns0:SiteEntity>
<ns0:SiteId>20</ns0:SiteId>
<ns0:SiteName>Ramada Jarvis (Comet) Hotel</ns0:SiteName>
</ns0:SiteEntity>
</ns0:SiteList>
<ns0:CourseList>
<ns0:CourseEntity>
<ns0:CourseId>50</ns0:CourseId>
<ns0:SiteId>10</ns0:SiteId>
</ns0:CourseEntity>
<ns0:CourseEntity>
<ns0:CourseId>10</ns0:CourseId>
<ns0:SiteId>10</ns0:SiteId>
</ns0:CourseEntity>
<ns0:CourseEntity>
<ns0:CourseId>20</ns0:CourseId>
<ns0:SiteId>20</ns0:SiteId>
</ns0:CourseEntity>
</ns0:CourseList>
</ns0:FindCoursesForOffenderResponse>
</s:Body>
</s:Envelope>
我想SiteName
为每个CourseEntity
. 例如对于CourseID = 50
应该SiteName
是Ramada Watford
。
到目前为止,我有这个 XSL,但它不起作用。
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://H.FindCoursesForOffenderResponse" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="html"/>
<xsl:param name="lnum">123</xsl:param>
<xsl:template match="/">
<html>
<body>
<ul>
<xsl:for-each select="s:Envelope/s:Body/ns0:FindCoursesForOffenderResponse/ns0:CourseList/ns0:CourseEntity">
<xsl:variable name="currEntity"><xsl:value-of select="ns0:SiteId"/></xsl:variable>
<xsl:value-of select="$currEntity"/><br/>
<xsl:for-each select="s:Envelope/s:Body/ns0:FindCoursesForOffenderResponse/ns0:SiteList/ns0:SiteEntity[ns0:SiteId=$currEntity]">
<li>
<xsl:value-of select="ns0:SiteName"/>
</li>
</xsl:for-each>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
第一个for-each
循环运行CourseEntities
,内部循环试图为每个课程 ID 找到相关的站点名称。
任何的想法?
输出
<couseID> - <sitename>
50 - Ramada Watford
20 - Ramada Jarvis (Comet) Hotel