Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2003, 08:05 AM
Authorized User
 
Join Date: Nov 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to generate an Error message from XSLT

Suppose i have an xml file, it is both valid and well formed, i have to write an xslt in such a way that it should display an error message if some condition is not satisified in the XSLT.

for example my xml file is like this.

<?xml version="1.0"?>
<emp>
    <name>srini</name>
    <name>rama</name>
    <name>ramesh</name>
    <name>srini</name>
    <name>ragi</name>
</enm>
here we have to display the names in such way that it should not display equal names twice. if an xml file is having like that then then it should generate one warning message like: "same names" .
is it possible to do like that?
please give a reply for this.
thanks.
regards,
srini.

srini
__________________
srini
 
Old December 16th, 2003, 10:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Use xsl:message element. How the message is displayed is system dependent.

Joe (MVP - xml)
 
Old December 16th, 2003, 10:50 AM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

srini,

I assume the document level element not being well formed was a typo <emp> … </enm>.

If the elements you are processing to catch duplicates are always siblings, as in your example, you can simply do something like:

<xsl:template match="name">
    <xsl:if test=". = preceding-sibling::name">
        ...do something...
    </xsl:if>
</xsl:template>

Now, the "do something" can vary depending on how you want to "capture" these errors. You can throw a message to standard output with <xsl:message>. For my stylesheets, I call an error template with an error code that looks up the appropriate text to output via the <xsl:message> element.

…sam







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to generate random numbers in xslt anboss XSLT 3 July 23rd, 2008 09:10 AM
Using XSLT to generate PDF with Japanese text XSLTUser XSLT 5 December 20th, 2007 09:01 PM
ASP files generate global.asa error ebenezer BOOK: Beginning ASP 3.0 3 November 24th, 2006 02:01 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
generate id grouping using xslt meetnaveen4u XSLT 0 May 23rd, 2005 05:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.