2015-12-21 83 views
0

列出的數據我有XML這樣的代碼我如何寫XSL代碼與條件

<hotels> 
    <hotel> 
     <name>hotel A</name> 
     <rating>5</rating> 
    </hotel> 
    <hotel> 
     <name>hotel B</name> 
     <rating>4</rating> 
    </hotel> 
    <hotel> 
     <name>hotel C</name> 
     <rating>2</rating> 
    </hotel> 
    <hotel> 
     .... 
    </hotel> 
</hotels> 

用我的老式question,我怎麼能在文件的.xsl寫XSL代碼與條件rating列表數據> = 4;

+0

請張貼自足的問題,包括XML輸入,一個完整的樣式和預期輸出。請參閱:http://stackoverflow.com/help/mcve –

+0

http://stackoverflow.com/help/someone-answers –

回答

1

如果您正在使用:

<xsl:for-each select="hotels/hotel"> 

將其更改爲:

<xsl:for-each select="hotels/hotel[rating >= 4]"> 

如果您正在使用:

<xsl:apply-templates select="hotel"/> 

將其更改爲:

<xsl:apply-templates select="hotel[rating >= 4]"/> 
1

讓所有的酒店名字評級> = 4在一個模板:

<xsl:template match="hotels/hotel/name[../rating >= 4]"> 
    ... 
</xsl:template> 
+0

請注意內置模板。 –

+0

Thx爲小費。 – zx485