In XSLT 1.0, XPath plays three crucial roles錛?/font>
聽First, it is used within templates for addressing into the document to extract data as it is being transformed.
Second, XPath syntax is used as a pattern language in the matching rules for templates.
Third, it is used to perform simple math and string manipulations via built-in XPath operators and functions.
XSLT 2.0 retains and strengthens this intimate connection with XPath 2.0 by drawing heavily on the new computational abilities of XPath 2.0.
In XSLT, the context is set via:
路聽聽聽聽聽聽聽聽 a template match (<xsl:template match="x"> ... </xsl:template>)
路聽聽聽聽聽聽聽聽 xsl:for-each
路聽聽聽聽聽聽聽聽 xsl:apply-templates
鍓嶈呯浉褰撲簬瀹氫箟鍑芥暟錛屽悗鑰呯浉褰撲簬璋冪敤鍑芥暟銆?/span>
鍦?/span>
xsl:template
涓紝
match
灞炴ч噰鐢ㄤ簡
XPath
琛ㄨ揪寮忥紝鐢ㄦ潵紜畾妯℃澘鐨勯傜敤瀵硅薄銆傚
match
灞炴х殑璁劇疆鏃訛紝
//X
絳変環浜?/span>
X
銆?/span>
鍦?/span>
xsl:apply-templates
涓紝
select
灞炴ч噰鐢ㄤ簡
XPath
琛ㄨ揪寮忥紝鐢ㄦ潵閫夋嫨瑕佸簲鐢ㄦā鏉跨殑鑺傜偣銆傚鏋滅渷鐣ヤ簡
select
灞炴э紝鍒欒〃紺哄綋鍓嶈妭鐐圭殑鎵鏈夊悗浠h妭鐐歸兘搴旂敤妯℃澘錛屽鏋滄湁浜涜妭鐐規病鐢ㄩ氳繃
xsl:template
瀹氫箟妯℃澘錛屽垯閲囩敤榛樿妯℃澘錛堟敞錛?/span>
IE
涓瓨鍦ㄩ粯璁ゆā鏉匡級銆傝緗?/span>
select
灞炴ф椂錛岃浠庢枃妗f牴錛?/span>
/
錛夊紑濮嬬殑緇濆璺緞鏉ラ夋嫨鑺傜偣錛屼絾鏄?/span>
/
鍙互鐪佺暐銆傛澶勫拰涓婇潰
match
灞炴у樊鍒緢澶э紝娉ㄦ剰鍖哄垎銆?/span>
娉ㄦ剰錛?/span>
1
錛?/span>
<xsl:template match="/">
聽聽
聽聽
聽
聽<xsl:apply-templates select="/" />
</xsl:template>
涓婇潰璇彞浼氬紩璧烽掑綊璋冪敤妯℃澘錛屾寰幆銆?/span>
2
錛夊鏋滃湪
XSL
鏂囦歡涓病鏈夊搴旀牴鐨勬ā鏉匡紝鍗蟲病鏈?/span>
<xsl:template match="/">
錛屽垯鍏朵粬鐨勬ā鏉塊兘浼氳浣跨敤銆備絾鏄紝濡傛灉鏂囦歡涓瓨鍦ㄥ搴旀牴鐨勬ā鏉匡紝闄ら潪浣跨敤
<xsl:apply-templates select="
鈥︹?/span>
" />
錛屽惁鍒欏叾浠栫殑妯℃澘閮戒笉浼氳浣跨敤銆?/span>
榪欐槸鍥犱負錛屽鏋滄病鏈夊搴旀牴鐨勬ā鏉匡紝
IE
浼氶噰鐢ㄩ粯璁ょ殑瀵瑰簲鏍圭殑妯℃澘錛岃岃繖涓粯璁ょ殑妯℃澘涓嬌鐢ㄤ簡
<xsl:apply-templates select="
鈥︹?/span>
" />
銆傝繖綾諱技浜?/span>
Java
涓粯璁ゆ瀯閫犲嚱鏁扮殑閲嶅啓錛屽鏋滄垜浠病鏈夊畾涔夛紝灝變嬌鐢ㄩ粯璁ょ殑銆?/span>