F
for.fun
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>
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>