|
Subject:
|
How to generate an Error message from XSLT
|
|
Posted By:
|
srini
|
Post Date:
|
12/16/2003 7:05:48 AM
|
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
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
12/16/2003 9:44:16 AM
|
Use xsl:message element. How the message is displayed is system dependent.
Joe (MVP - xml)
|
|
Reply By:
|
shbyland
|
Reply Date:
|
12/16/2003 9:50:43 AM
|
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
|