Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

XML XSL Message

Hi,

I am trying below example


https://www.tutorialspoint.com/xslt/xslt_message.htm
My code is as below
<?xml version = "1.0"?> 
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?> 
<class> 
   <student rollno = "393"> 
      <firstname>Dinkar</firstname> 
      <lastname>Kad</lastname> 
      <nickname>Dinkar</nickname> 
      <marks>85</marks> 
   </student> 
   <student rollno = "493"> 
      <firstname></firstname> 
      <lastname>Gupta</lastname> 
      <nickname>Vinni</nickname> 
      <marks>95</marks> 
   </student> 
   <student rollno = "593"> 
      <firstname>Jasvir</firstname> 
      <lastname>Singh</lastname> 
      <nickname>Jazz</nickname> 
      <marks>90</marks> 
   </student> 
</class>

Open in new window

<?xml version = "1.0" encoding = "UTF-8"?> 
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">   
   <xsl:template match = "/"> 
      <html> 
         <body> 
            <h2>Students</h2> 
            <table border = "1"> 
               <tr bgcolor = "#9acd32"> 
                  <th>Roll No</th> 
                  <th>First Name</th> 
                  <th>Last Name</th> 
                  <th>Nick Name</th> 
                  <th>Marks</th> 
               </tr> 
					
               <xsl:for-each select = "class/student"> 
					
                  <xsl:if test = "firstname = ''"> 
                     <xsl:message terminate = "yes">A first name field is empty. 
                     </xsl:message> 
                  </xsl:if> 
					
                  <tr> 
                     <td><xsl:value-of select = "@rollno"/></td> 
                     <td><xsl:value-of select = "firstname"/></td> 
                     <td><xsl:value-of select = "lastname"/></td>
                     <td><xsl:value-of select = "nickname"/></td> 
                     <td><xsl:value-of select = "marks"/></td> 
                  </tr> 
               </xsl:for-each> 
            </table> 
         </body> 
      </html> 
   </xsl:template>
</xsl:stylesheet>

Open in new window

i am getting below wrong output without message. please advise on how to fix it


Dinkar Kad Dinkar 85   Gupta Vinni 95  Jasvir Singh Jazz 90
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

If you are looking for an iterator and catch/throw, you need to use XSLT3

can you point to good examples in xslt3.
looks like tutorialpoint examples based on xslt2
well, the only two processor supporting XSLT3 is
- Saxon 9.6 and above
but you do need a paid version in order to use XSLT3 (Saxon professional edition or enterprise edition)
that processor comes with a bunch of examples that are a bit useless without the processor itself
- exselt (http://exselt.net/)
you can download a beta, but that one is dot net only