Reputation: 183
My Problem ist that my stylesheet isn't maching my xml file correctly. If comment out the template for Machine
-tag, i see my table of Errors, if i have the stylesheet like I posted it here, I only see the generated link of my Machine-tag, but none of the errors.
I have the following XML Source file:
XML:
<Machine HtmlUri="http://stackoverflow.com" Name="XY1">
<Errors Count="2">
<Error>
<TimeStamp>2013-11-12T07:27:24.9766747+01:00</TimeStamp>
<Machine>XY1</Machine>
<Message> ... </Message>
<InnerException />
<StackTrace> ... </StackTrace>
</Error>
<Error>
<TimeStamp>2013-11-12T07:27:24.9766747+01:00</TimeStamp>
<Machine>XY1</Machine>
<Message> ... </Message>
<InnerException />
<StackTrace> ... </StackTrace>
</Error>
</Errors>
</Machine>
And I have this stylesheet. I'm not very familiar with xslt and all my research on sites like w3school.com could not help me.
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<body>
<h2>Status File</h2>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="Machine">
<h5>Machine Information:</h5>
<div>
<a href="{@HtmlUri}" target="_blank">
<xsl:apply-templates select="@HtmlUri" />
</a>
</div>
</xsl:template>
<xsl:template match="Errors">
<h5>Errors:</h5>
<div>
<table border="1">
<tr bgcolor="#dd0000">
<th>Machine</th>
<th>TimeStamp</th>
<th>Message</th>
</tr>
<xsl:for-each select="Error">
<tr bgcolor="ff0000">
<td>
<xsl:value-of select="./Machine"/>
</td>
<td>
<xsl:value-of select="./TimeStamp"/>
</td>
<td>
<xsl:value-of select="./Message"/>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2
Views: 404
Reputation: 183
According to some usefull comments I solved my problem.
Hence I needed a quite generic XSLT-template I decided to apply the other templates in my Machine
-template.
That's my working XSLT now:
[...]
<xsl:template match="Machine">
<h5>Machine Information:</h5>
<div>
<a href="{@HtmlUri}" target="_blank">
<xsl:apply-templates select="@HtmlUri" />
</a>
</div>
<xsl:apply-templates />
</xsl:template>
[...]
Upvotes: 1