473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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>

Dec 6 '05 #1
2 1224
fo*****@laposte.net 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/

Dec 6 '05 #2

Peter Flynn a écrit :

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

Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wil | last post by:
I'm very new to developing in .NET and even newer to XML. The past few days have been pretty frustrating for me because I'm trying to perform a transform on data in a dataset and it's not working....
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
2
by: Paolo Pignatelli | last post by:
I am trying to work the example on http://support.microsoft.com/default.aspx?scid=kb;EN-US;q315888 . I follow esxactly the advice (I beleive): Here are the files: WebForm1.aspx: -- .......
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
2
by: Bogdan Zamfir | last post by:
Hi, I have a problem with err.raise I write a class module, and I want to use this mechanism to indicate errors when user set wrong values to properties But it seems the error is never raised...
6
by: Christopher | last post by:
I am currently in the process of evaluating the performance hits of moving to the .NET platform for our application. I created a sample project that loads the transforms the same XML and XSLT in...
1
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
5
by: Gilgamesh | last post by:
Hi. I'm looking for an easy way to generate, automatically, an XSLT from an XSD, to be applied to a XML file (conforming the previous XSD) and generate an HTML. Many of you will tell me that...
2
by: trash.muell | last post by:
Hi, I am struggling with an XSLT task and need a hint: I have a complex XML file but want to only output some sub-trees of the XML structure. My XSLT script is always printing the information of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.