我在使用XPath和包含函数时遇到问题。试想一下,下面的XML例子:xpath包含()函数的工作方式
<movie-selection>
<film>
<name>Hunger Games - Catching Fire</name>
<release>2013</release>
<description>Katniss Everdeen and Peeta Mellark are once again forced to fight for there lifes in the Hunger Games. There Victory the previous year kick starts a rebellion againist the Capitol and President Snow.
</description>
<runtime>146 minutes</runtime>
<stars>Jennifer Lawrence, Josh Hutcherson, Liam Hemsworth</stars>
<genre>Adventure, Sci-Fi</genre>
<rating>4.8</rating> </film>
<film>
<name>Avatar</name>
<release>2009</release>
<description>A paraplegic Marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.
</description>
<runtime>162 minutes</runtime>
<stars> Sam Worthington, Zoe Saldana, Sigourney Weaver</stars>
<genre>Adventure, Fantasy, Action</genre>
<rating>4.5</rating>
我想回到那个有“行动”在类型属性这所有的电影是什么,我现在有,但它是不是加工。任何人都能看到我的错误?
movie-selection/film[contains(genre, 'Action')]
任何帮助表示赞赏。
<xsl:for-each select="movie-selection/film">
<xsl:if test="/movie-selection/film[contains(genre, 'Drama')]">
<p><xsl:value-of select="name"/></p>
<p><xsl:value-of select="release"/></p>
<p><xsl:value-of select="runtime"/></p>
<p><xsl:value-of select="description"/></p>
<p><xsl:value-of select="stars"/></p>
<p><xsl:value-of select="genre"/></p>
<p><xsl:value-of select="rating"/></p>
</xsl:if>
</xsl:for-each>
它返回一切。
在你的榜样,1)'genre'不是一个属性,但是一个元素2)没有'genre'包含的行动值”。 – BoltClock
我只看到缺少的是一个主要的斜线,例如'/ movie-selection/film [contains(genre,'Action')]''。将其更改为* Adventure *并获得一个匹配,请参阅http://www.xpathtester.com/obj/65cee161-dbc1-46a3-a29a-ab1b4360fee9 – Phil
它似乎在路径测试程序中正常工作而不是xsl文件 – Nic