Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [XSLT] Can not raise some information from a XML sub-node

Reply
Thread Tools

[XSLT] Can not raise some information from a XML sub-node

 
 
for.fun@laposte.net
Guest
Posts: n/a
 
      12-06-2005
Hi everybody,

I have to transform an input XML into an output XML using a XSLT style
sheet.
On the input side, the information is stored into sub-nodes.
On the output side, I need to transform the country codes into country
names and report any transform error.
The only requirement is the error must be reported at the root level
("foo123" will cause the error in my following sample)

In order to do it, I use "template match" instructions.
When I am inside the "<code>foo123<code>" block, I did not find any way
to save the error or to raise it to the output root token.

You know that XSLT variables have only a local scope and can only be
instancied once. So I can not use them to save an error status and use
it later.

The brute-force issue would be to prune all the XML tree at the end of
the processus only to check for errors and then report them at the root
level but I am sure there is a better way to do it.


Can anyone help me ?


Thanks in advance.


----- XML samples -----

In the following sample, the error is due to "foo123" which is not a
country code.

* INPUT XML *

<root>
<group>
<country>
<code>44</code>
</country>
<country>
<code>33<code>
</country>
<country>
<code>foo123<code>
</country>
<group>
</root>


* OUTPUT XML *

<root>
<errcode>TRANSFORM_ERROR<errcode>
<countrynames>
<name>ENGLAND</name> <!-- code 44 -->
<name>FRANCE</name> <!-- code 33 -->
</countrynames>
</root>

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      12-06-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi everybody,
>
> I have to transform an input XML into an output XML using a XSLT style
> sheet.
> On the input side, the information is stored into sub-nodes.
> On the output side, I need to transform the country codes into country
> names and report any transform error.
> The only requirement is the error must be reported at the root level
> ("foo123" will cause the error in my following sample)
>
> In order to do it, I use "template match" instructions.
> When I am inside the "<code>foo123<code>" block, I did not find any
> way to save the error or to raise it to the output root token.
>
> You know that XSLT variables have only a local scope and can only be
> instancied once. So I can not use them to save an error status and use
> it later.
>
> The brute-force issue would be to prune all the XML tree at the end of
> the processus only to check for errors and then report them at the
> root level but I am sure there is a better way to do it.


This is one of those occasions when xsl:for-each is the right tool.

> ----- XML samples -----
>
> In the following sample, the error is due to "foo123" which is not a
> country code.
>
> * INPUT XML *
>
> <root>
> <group>
> <country>
> <code>44</code>
> </country>
> <country>
> <code>33<code>
> </country>
> <country>
> <code>foo123<code>
> </country>
> <group>
> </root>


<xsl:template match="root">
<xsl:for-each select="descendant::code">
<xsl:if test="your_test_for_code_values">
<errcode>
<xsl:text>Invalid code: </xsl:text>
<xsl:value-of select="."/>
</errcode>
</xsl:if>
</xsl:for-each>
</xsl:template>

> <root>
> <errcode>TRANSFORM_ERROR<errcode>
> <countrynames>
> <name>ENGLAND</name> <!-- code 44 -->
> <name>FRANCE</name> <!-- code 33 -->
> </countrynames>
> </root>


///Peter
--
XML FAQ: http://xml.silmaril.ie/

 
Reply With Quote
 
 
 
 
for.fun@laposte.net
Guest
Posts: n/a
 
      12-08-2005

Peter Flynn a écrit :

Thanks of lot.
It works fine and fast.
This is all what I expected !

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Raise X or Raise X()? bvdp Python 10 03-12-2012 04:08 PM
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
raise Exception or raise Exception() ernest Python 2 11-14-2010 08:14 PM
raise or not to raise [Newbie] Jacol Python 5 02-05-2007 11:46 PM
Registration opens for XML 2005; Respected XML Forum Delivers Practical Information That Attendees Can Put to Immediate Use within Their Organizations melledge XML 0 07-21-2005 07:27 PM



Advertisments