I am having problems with formating the display of the XML into HTML with XSL.
I have the following XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Send_Email>
<Send_Email_lookupID>HIDE_REJECT</Send_Email_lookupID>
<Error_Message>REJECT1</Error_Message>
<Error_Message>REJECT2</Error_Message>
<Error_Message>REJECT3</Error_Message>
</Send_Email>
And the XSL:
<?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>Result</h2>
<table border="1">
<xsl:for-each select="/Send_Email">
<xsl:if test="not(/Send_Email_lookupID)">
<tr>
<td><xsl:value-of select="*"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This line is always static and should be hidden:
<Send_Email_lookupID>HIDE_REJECT</Send_Email_lookupID>
The next set of lines may be different everytime, but all need to be displayed.
Can anyone help me out here?
Thanks in Advance.
Update – Correct Solution
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Result</h2>
<table border="1">
<xsl:for-each select="Send_Email/*[local-name()!='Send_Email_lookupID']">
<tr>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I assume that you want a table with one row for each error message – than what you are looking for is:
/Send_Email_lookupIDmatches a root element because it starts with/– but in your XML the element with that name is not the root one.If you don’t want to match just
Error_Messagebut EVERY element underSend_EmailexceptSend_Email_lookupIDuse:that means ‘all the elements under
Send_Emailexcept those namedSend_Email_lookupID.Note also that
<xsl:value-of select="*"/>outputs the text contained inside all sub-elements of the current node – whereas<xsl:value-of select="."/>outputs the text contained in the current node – that is what we want in this case.