suppose i have this xml:
<college>
<student>
<name>amit</name>
<file>/abc/kk/final.c</file>
<rollno>22</rollno>
</student>
<student>
<name>sumit</name>
<file>/abc/kk/up.h</file>
<rollno>23</rollno>
</student>
<student>
<name>nikhil</name>
<file>/xyz/up.cpp</file>
<rollno>24</rollno>
</student>
<student>
<name>bharat</name>
<file>/abc/kk/down.h</file>
<rollno>25</rollno>
</student>
<student>
<name>ajay</name>
<file>/simple/st.h</file>
<rollno>27</rollno>
</student>
</college>
i am using for-each in ".xsl" to display all the entries of nodes, but i only want to display the entries of those node only in which file name starts with "/abc/kk" as i am new to xslt..
please provide me solution.
i am using :
<xsl:for-each select="college/student">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="file"/></td>
<td><xsl:value-of select="rollno"/></td>
</tr>
This transformation:
when applied to the provided XML document:
produces the wanted, correct result:
Explanation:
A template matching any
student
having afile
child whose string value starts with '/abc/kk'. This just puts the generated contents in a wrappertr
element.A template matching any
student
that has no body and effectively deletes it (doesn't copy this element to the output). This template has a lower priority than the first one, because the first one is more specific. Therefore, onlystudent
elements that are not matched by the first template are processed with the second template.A template matching any child element of any
student
element. This just wraps the content into atd
element.Like this:
The brackets
[ ]
delimit a "filter", and inside that filter you can have functions likestarts-with()
Also you can use
[..]
inmatch
: