473,605 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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">
  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>
  15.   <xsl:template match="text()">
  16.     <xsl:copy-of select="."/>
  17.   </xsl:template>
  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>
  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>
  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 "rescheduleReas on". I guess it is trying to look for exact value of 'prefix2:Appoin tmentEvent' but by xml has 'abc2:Appointme ntEvent'.

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.

Oct 30 '09 #1
3 7198
8,658 Recognized Expert Moderator Expert
attribute values do not have a namespace (though the attribute nodes have). therefore xsi:type='prefi x2:AppointmentE vent' does not exist in your original XML, no matter what the prefix2 namespace is. use [@xsi:type='abc2 :AppointmentEve nt'] as condition
Oct 30 '09 #2
2 New Member
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
8,658 Recognized Expert Moderator Expert
how do you mean that?
Nov 1 '09 #4

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

Similar topics

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* xmlDoc = parser->getDocument(); xercesc::DOMNodeList* list;
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 2003 - Windows XP Pro PC suscessfully. But when I ran it from the command line - C:\Documents and Settings\SHC\My Documents\Visual Studio Projects\XMLdtdValidatingReader\Debug>XMLdtdValidatingReader valcanoes.xml, I got the following message in...
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 xsi:type="DerivedClass" attribute and the Instance Namespace. When I attempt to validate the xml upon deserialization the XmlValidatingReader chokes on this attribute value. I can't seem to find a way around this. Any suggestions?
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 outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang of it, another problem arose: I can't seem to access the "xsi:type" attribute. That is, the XML file looks
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 of it, another problem arose: I can't seem to access the "xsi:type" attribute. That is, the XML file looks something like this: <situation>
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 FileStream(NavCmdFile, FileMode.Create, FileAccess.Write, FileShare.None); XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:ucles.cbtas.model.Centre"> <number>25279</number> <customer-id>16</customer-id> </centre>
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, <PrescriptionRefillMeds> <anyType xsi:type="PrescriptionRefillMed"> <Description>Drug1</Description> I have written code to conert the object in to the serialising/deserialising in C#. XSLT has the required namespacses also,not able to read the...
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 additional TWO extra fields from the standard customer type. UK customer additionaly have CustomerCounty & CustomerPostcode Non-UK European have CustomerAddressline5(optional) & Timezone(I dont need to print this) However in my XSL I'm...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.