这是XML的缩减片段:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="WEEK-AYFM.xsl"?>
<MeetingWorkBook>
<Meeting>
<LAC CircuitVisit="0">
<SongEnd Title="“This Is the Way”" StartTime12="8:55" StartTime24="20:55" EndTime12="9:00" EndTime24="21:00">65</SongEnd>
<PrayerEnd>Brother 8</PrayerEnd>
</LAC>
</Meeting>
</MeetingWorkBook>
这是一些调用XSL:
<xsl:template match="LAC">
<table class="tableLAC">
<xsl:apply-templates select="SongEnd">
<xsl:with-param name="strPrayerEnd">
<xsl:value-of select="PrayerEnd"/>
</xsl:with-param>
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="SongEnd">
<xsl:param name="strPrayerEnd" />
<tr>
<td class="cellTime">
<xsl:value-of select="@EndTime24"/>
</td>
<td>
<div class="floatRight">
Prayer:
</div>
<span class="bulletLAC">•</span>
<span class="textSongLabel">Song</span>
<span class="textSongNumber">
<xsl:value-of select="."/>
</span>
</td>
<td>
<xsl:value-of select="$strPrayerEnd"/>
</td>
</tr>
</xsl:template>
SongEnd 模板是否可以直接访问 PrayerEnd 值而不将其作为参数传递?
答案 0 :(得分:2)
在匹配<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="list-group">
<li class="list-group-item text-right">
<p>Cras justo odio</p>
<span class="glyphicon glyphicon-search"></span>
</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
的模板中,上下文节点是SongEnd
元素。然后,您可以使用简单的XPath表达式来选择模板中相对于上下文节点的SongEnd
节点。
例如,如果PrayerEnd
始终是PrayerEnd
的以下兄弟,您可以写
SongEnd
不使用参数。
答案 1 :(得分:1)
正如我在评论中所说,我相信你会让它变得比它需要的更复杂。以下任一样式表都会产生与当前样式表相同的结果:
<强> 1 强>
<xsl:template match="LAC">
<table class="tableLAC">
<tr>
<td class="cellTime">
<xsl:value-of select="SongEnd/@EndTime24"/>
</td>
<td>
<div class="floatRight">
Prayer:
</div>
<span class="bulletLAC">•</span>
<span class="textSongLabel">Song</span>
<span class="textSongNumber">
<xsl:value-of select="SongEnd"/>
</span>
</td>
<td>
<xsl:value-of select="PrayerEnd"/>
</td>
</tr>
</table>
</xsl:template>
<强> 2 强>
<xsl:template match="LAC">
<table class="tableLAC">
<tr>
<xsl:apply-templates select="SongEnd"/>
<td>
<xsl:value-of select="PrayerEnd"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="SongEnd">
<td class="cellTime">
<xsl:value-of select="@EndTime24"/>
</td>
<td>
<div class="floatRight">
Prayer:
</div>
<span class="bulletLAC">•</span>
<span class="textSongLabel">Song</span>
<span class="textSongNumber">
<xsl:value-of select="."/>
</span>
</td>
</xsl:template>
第3 强>
<xsl:template match="LAC">
<table class="tableLAC">
<tr>
<xsl:apply-templates/>
</tr>
</table>
</xsl:template>
<xsl:template match="SongEnd">
<td class="cellTime">
<xsl:value-of select="@EndTime24"/>
</td>
<td>
<div class="floatRight">
Prayer:
</div>
<span class="bulletLAC">•</span>
<span class="textSongLabel">Song</span>
<span class="textSongNumber">
<xsl:value-of select="."/>
</span>
</td>
</xsl:template>
<xsl:template match="PrayerEnd">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>