469,302 Members | 2,087 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,302 developers. It's quick & easy.

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 6596
Dormilich
8,651 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,651 Expert Mod 8TB
how do you mean that?
Nov 1 '09 #4

Post your reply

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

Similar topics

3 posts views Thread by keepyourstupidspam | last post: by
2 posts views Thread by Jason Cartwright | last post: by
reply views Thread by Carl Lindmark | last post: by
1 post views Thread by PeterW | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.