473,394 Members | 1,752 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,394 software developers and data experts.

how to retrieve node and child values that has xsi:type value

I have the below input XML sent by APP1.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <abc1:QWAARequest 
  3.   xmlns:abc1="http://www.mysite.com/myLink/v1/Test.xsd" 
  4.   xmlns:abc2="http://www.mysite.com/v1" 
  5.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  6.   xsi:schemaLocation="http://www.mysite.com/myLink/v1/Test.xsd Test.xsd">
  7.     <abc1:HostID>TEST</abc1:HostID>
  8.     <abc1:WorkForceEvent>
  9.         <abc2:ProjectElementHasCalendarEntry>
  10.             <abc2:relationshipType>ConfirmedSlot</abc2:relationshipType>
  11.             <abc2:CalendarEntry xsi:type="abc2:AppointmentEvent">
  12.                 <abc2:rescheduleReason>Standard Prefix</abc2:rescheduleReason>
  13.             </abc2:CalendarEntry>
  14.         </abc2:ProjectElementHasCalendarEntry>
  15.     </abc1:WorkForceEvent>
  16. </abc1:QWAARequest>
Another application APP2 sends a different XML file with different prefixes (say xyz1, xyz2 in place of abc1, abc2 in above xml) but with same namespace.

I am trying to build a generic xsl which can work with both xml files. Below is the same:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" 
  3.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  4.                 xmlns:prefix1="http://www.mysite.com/myLink/v1/Test.xsd"  
  5.                 xmlns:prefix2="http://www.mysite.com/v1" 
  6.                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  7.  
  8.   <xsl:template match="*">
  9.     <xsl:element name="{name()}">
  10.       <xsl:copy-of select="@*"/>
  11.       <xsl:apply-templates select="node() | text()"/>
  12.     </xsl:element>
  13.   </xsl:template>
  14.  
  15.   <xsl:template match="text()">
  16.     <xsl:copy-of select="."/>
  17.   </xsl:template>
  18.  
  19.   <xsl:template match="prefix1:*">
  20.     <xsl:element name="prefix1:{local-name()}">
  21.       <xsl:copy-of select="@*"/>
  22.       <xsl:apply-templates select="node() | text()"/>
  23.     </xsl:element>
  24.   </xsl:template>
  25.  
  26.   <xsl:template match="prefix2:*">
  27.     <xsl:element name="prefix2:{local-name()}">
  28.       <xsl:copy-of select="@*"/>
  29.       <xsl:apply-templates select="node() | text()"/>
  30.     </xsl:element>
  31.   </xsl:template>
  32.  
  33.   <xsl:template match="prefix1:QWAARequest">
  34.         <Output>
  35.       <xsl:value-of select="prefix1:HostID"/> |
  36.       <xsl:value-of select="prefix1:WorkForceEvent/prefix2:ProjectElementHasCalendarEntry/prefix2:relationshipType" /> |
  37.       <xsl:value-of select="prefix1:WorkForceEvent/prefix2:ProjectElementHasCalendarEntry[prefix2:relationshipType='ConfirmedSlot']/prefix2:CalendarEntry[@xsi:type='prefix2:AppointmentEvent']/prefix2:rescheduleReason" />
  38.     </Output>
  39.     </xsl:template>
  40. </xsl:stylesheet>
The above xsl works fine except where it tries to get the value for "rescheduleReason". I guess it is trying to look for exact value of 'prefix2:AppointmentEvent' but by xml has 'abc2:AppointmentEvent'.

Please suggest how to modify the xsl to interpret the value correctly.

I am using .Net 2.0 programming model to load the xml and xsl to generate the output.

Cheers
Rajani
Oct 30 '09 #1
3 7174
Dormilich
8,658 Expert Mod 8TB
@drajani
attribute values do not have a namespace (though the attribute nodes have). therefore xsi:type='prefix2:AppointmentEvent' does not exist in your original XML, no matter what the prefix2 namespace is. use [@xsi:type='abc2:AppointmentEvent'] as condition
Oct 30 '09 #2
Thanks. That way I can never write a generic xsl. Is there any possibility to add a match condition in a template tag which can do a find & replace or something similar (as a workaround)?
Oct 30 '09 #3
Dormilich
8,658 Expert Mod 8TB
how do you mean that?
Nov 1 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: keepyourstupidspam | last post by:
Hi, I am using xerces dom C++, I want to change an element value, here is the code I am using but the element in the file is not getting updated. ... ... ... xercesc_2_4::DOMDocument*...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
0
by: Carl Lindmark | last post by:
Hello all, I'm having some problems understanding all the ins and outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang...
6
by: geoffrobinson | last post by:
Hi, I'm serializing an object using XmlSerializer. It is serializing, but we are getting errors upon deserialization. We use the following code to serialize: FileStream fs = new...
1
by: PeterW | last post by:
I have a bit of xml that I am trying to create an xsd schema from. A very simplified version is as follows: <?xml version="1.0" encoding="UTF-8"?> <centre...
0
by: Umagowder | last post by:
All I have my class serialised correctly. I have to apply style sheet to that data and display it in some other format. Everything works fine,I can not read the following xml tag, ...
8
by: robtyketto | last post by:
Greetings, My XML schema defines a customer to be of type UK or Non-UK European making use of xsi:type. The difference between the complex UK and Non-UK European customer types is they have an...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.