2017-09-06 18 views
0

下記の結果を得るフィルタリングXSLスタイルシートを構築するためにそこの方法です:は、複数の同一のノード名とXMLを与えられ、このXMLを考える

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <results> 
     <activityDescription>reservation</activityDescription> 
    </results> 
    <results> 
     <studentSet>year1</studentSet> 
     <studentSet>year2</studentSet> 
     <studentSet>year3</studentSet> 
     <studentSet>year4</studentSet> 
     <activityDescription>Math</activityDescription> 
    </results> 
    <results> 
     <studentSet>1g</studentSet> 
     <studentSet>2h</studentSet> 
     <studentSet>3j</studentSet> 
     <studentSet>4k</studentSet> 
     <activityDescription>Science</activityDescription> 
    </results> 
    <results> 
     <studentSet>year 2</studentSet> 
     <activityDescription>XSL/XML</activityDescription> 
    </results> 
</root> 

と、このXSLTコード:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:param name="year" select="1"/> 
<xsl:template match="/"> 
    <html> 
    <body> 
    <h2>Schedules</h2> 
    <table border="1"> 
     <tr> 
     <th>Activity</th> 
     <th>Year</th> 
     </tr> 
     <xsl:for-each select="//results[contains(studentSet,$year)]"> 
     <tr> 
     <td><xsl:value-of select="activityDescription" /></td> 
     <td><xsl:value-of select="studentSet" /></td> 
     </tr> 
     </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

結果は、param $ year = 1の2行(数学、科学)を表示しますが、contains()関数は最初の文字のみを表示するため、$ year = 4は表示されません。どうすればこれを達成できますか?

答えて

2

代わりにresults[studentSet[contains(.,$year)]]を使用してください。

関連する問題