 |
| 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
|
|
|
|

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

April 22nd, 2010, 06:00 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
could any one suggest me a idea!
Thanks,
divya
|
|

April 22nd, 2010, 06:07 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

April 22nd, 2010, 06:12 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
You haven't told us what you'd like your output XML to look like.
|
|

April 22nd, 2010, 10:57 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 22nd, 2010, 11:04 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

April 22nd, 2010, 11:13 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks Micheal.
|
|
 |