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 April 21st, 2010, 11:43 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Error hadling in XSLT

Hi Frnds,

My Upstream will send the response in the form of XML. This xml may some time contains error messages or errorcodes i.e
<errorInfo errText="Error : Could not update user details."/> .some times it returns errorcode instead of errText i.e
<errorInfo errCode="50001"/>.
I wrote xslt to handle errText as below.how to generalize the XSLT to take either errorcode or errortext or both basing on the response XML.

<xsl:if test="o:Response /o:Result/o:errorCount!=0">
<ErrorDetails>
<xsl:attribute name="MESSAGE"><xsl:value-of select="o:Response /o:Result/o:errorInfo/@errText"/></xsl:attribute>
<ErrorDetails>
<SUCCESS> N</SUCCESS>
</xsl:if>

Thanks,
Divya
 
Old April 22nd, 2010, 06:00 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default

could any one suggest me a idea!

Thanks,
divya
 
Old April 22nd, 2010, 06:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not entirely sure what your problem is but why don't you simply output both:

Code:
<xsl:attribute name="MESSAGE">
  <xsl:value-of select="o:Response /o:Result/o:errorInfo/@errCode"/>
  <xsl:value-of select="o:Response /o:Result/o:errorInfo/@errText"/>
</xsl:attribute>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 22nd, 2010, 06:12 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You haven't told us what you'd like your output XML to look like.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old April 22nd, 2010, 10:57 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hello,

Please find my input,xslt and output xml.

input xml:
<Response>
<Result>
<errorInfo errText="Error : Could not update user details."/>
<errorInfo errCode="5668"/>
<errorInfo errCode="5669"/>
<errorInfo errCode="5670"/>
<errorInfo errCode="5671"/>
<warningCount>0</warningCount>
<errorCount>4</errorCount>
</Result>
</Response>

now i have to print errText,errCode totally 5 messages.
my xslt is not printing errText. it is printing only errCode values

<xsl:for-each select="o:Response/o:Result/o:errorInfo">
<ErrorDetails>
<xsl:attribute name="MESSAGE"><xsl:value-of select="@errText"/></xsl:attribute> -->
<xsl:attribute name="MESSAGE"><xsl:value-of select="@errCode"/></xsl:attribute>
<ErrorDetails>
</xsl:for-each>

expected output xml should be like
<Row>
<ErrorDetails MESSAGE="Could not update user details" />
<ErrorDetails MESSAGE="50668" />
<ErrorDetails MESSAGE="50669" />
<ErrorDetails MESSAGE="50670" />
<ErrorDetails MESSAGE="50671" />
</Row>

with the above xslt i am not getting errText value .

Thanks
 
Old April 22nd, 2010, 11:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please use the code I suggested in my previous response.

If you create two attributes with the same name, the first is silently ignored.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 22nd, 2010, 11:13 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Micheal.





Similar Threads
Thread Thread Starter Forum Replies Last Post
text hadling macros shortman_alan Excel VBA 7 January 7th, 2009 05:30 PM
Error with XSLT deekshan XSLT 2 July 28th, 2008 03:53 AM
XSLT Decleration Error. lafilip XSLT 8 July 20th, 2006 04:33 PM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM





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