Reputation: 720
I am trying to display an XML tag attribute via xslt but am having trouble figuring it out.
My xml file looks similar to this:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="results.xsl"?>
<search command="grep -n -i -I htm C:\firebreath\*">
<match number="1">
<filename>C:\firebreath\CMakeLists.txt </filename>
<linenum>10 </linenum>
<matchstring># http://www.gnu.org/licenses/lgpl-2.1.html</matchstring>
</match>
</search>
And my XSLT file looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>grep matches </h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>filename</th>
<th>line number</th>
<th>match string</th>
</tr>
<xsl:for-each select="search/match">
<tr>
<td><xsl:value-of select="filename"/></td>
<td><xsl:value-of select="linenum"/></td>
<td><xsl:value-of select="matchstring"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
I want to display the command portion of the search tag before I begin to parse through the rest. Is there any way do to that? If so, how? A search didn't turn up anything particularly relevant...
Upvotes: 3
Views: 14554
Reputation: 243469
I want to display the command portion of the search tag before I begin to parse through the rest.
Read about the <xsl:value-of>
XSLT instruction.
And use:
<xsl:value-of select="/search/@command"/>
Upvotes: 5