2015-12-21 79 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