[英]for-each in xslt 1.0
如何在xsl中进行for-each? 我了解到每个元素,但我真的很感谢indet示例。
您需要将<xsl:for-each select= "database/sims/sim[simID = $callsimID]">
更改为<xsl:for-each select= "/database/sims/sim[simID = $callsimID]">
确保您从文档节点/
下选择sim
元素。
但是,我将定义一个键<xsl:key name="sim" match="sims/sim" use="simID"/>
并使用<xsl:for-each select="key('sim', $callsimID)">
,那应该更有效率。
这非常简单,您根本不需要<xsl:for-each>
。 另外,您确实应该将样式表模块化。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Customers</title>
</head>
<body>
<xsl:apply-templates select="database" />
</body>
</html>
</xsl:template>
<xsl:template match="database">
<table rules="all">
<caption>Customers</caption>
<xsl:apply-templates select="
sims/sim[
simID = current()/calls/call[
countryCodeOfOtherParty = '49'
and areaCodeOfOtherParty = '31'
and numberCodeOfOtherParty ='124567'
]/simID
]
" />
</table>
</xsl:template>
<xsl:template match="sim">
<tr>
<td><xsl:value-of select="customerID" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
哪里
sims/sim[
simID = current()/calls/call[
countryCodeOfOtherParty = '49'
and areaCodeOfOtherParty = '31'
and numberCodeOfOtherParty ='124567'
]/simID
]
毫不奇怪,这意味着“每个呼叫该特定号码的SIM卡” 。 请注意,使用current()
函数来引用XPath中间的<database>
。
您可以使用<xsl:key>
来提高性能,但是最后,仅当<database>
很大并且样式表变得缓慢时才需要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.