473,666 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XLS formatting based on Complex Element type where Xsi-Type = ??

108 New Member
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 & CustomerPostcod e
Non-UK European have CustomerAddress line5(optional) & Timezone(I dont need to print this)

However in my XSL I'm hardcoding the selecting of element names in (see code below).

I've looked at <xsl:if> but dont know how to compare the complex xsi type.

Can anyone help please to suggest away I only print the fields based on the xsi type?

Also as elemnt addresslline5 is optional for complex type NonUKEuropean customer is there a way to check if the field is present i.e. nulls before selectign the value?

I guess I could just reference all fields and if there empty or not present they wont print, but I'm sure there's a much better solution outthere.

Thanks
Rob

Extract from XML file.
Expand|Select|Wrap|Line Numbers
  1. <Customer xsi:type="UKCustomer">
  2.  
  3. <CustomerName>Ford Motors</CustomerName>
  4.  
  5. <CustomerCode>123456789A</CustomerCode>
  6.  
  7. <CustomerAddressLine1>10 Harvard Road</CustomerAddressLine1>
  8.  
  9. <CustomerAddressLine2>Fenton</CustomerAddressLine2>
  10.  
  11. <CustomerAddressLine3>Stoke-on-Trent</CustomerAddressLine3>
  12.  
  13. <CustomerAddressLine4>Staffordshire</CustomerAddressLine4>
  14.  
  15. <CustomerCountry>United Kingdom</CustomerCountry>
  16.  
  17. <CustomerSigneeName>Trevor Thames</CustomerSigneeName>
  18.  
  19. <CustomerSigneeSignature>T.Thames</CustomerSigneeSignature>
  20.  
  21. <CustomerPostCode>ST2 9DS</CustomerPostCode>
  22.  
  23. </Customer>
Extract from XSL File
Expand|Select|Wrap|Line Numbers
  1. <td align="justify" valign="top">
  2.  
  3. <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerName"/><br/>
  4.  
  5. <xsl:value-of 
  6. select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine1"/><br/>
  7.  
  8. <xsl:value-of 
  9. select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine2"/><br/>
  10.  
  11. <xsl:value-of 
  12. select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine3"/><br/>
  13.  
  14. <xsl:value-of 
  15. select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine4"/><br/>
  16.  
  17. <xsl:value-of 
  18. select="my:PODBatch/my:POD/my:Customer/my:CustomerCountry"/><br/>
  19.  
  20. <xsl:value-of 
  21. select="my:PODBatch/my:POD/my:Customer/my:CustomerPostcode"/><br/>
  22.  
  23. </td>
Nov 7 '07 #1
8 3957
jkmyoung
2,057 Recognized Expert Top Contributor
If you're going to be printing each non-empty element out, you could do the following:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="my:PODBatch/my:POD/my:Customer/*[.!='']"><!-- select all non-empty elements -->
  2.   <xsl:value-of select="."/><br/>
  3. </xsl:for-each>
Otherwise, you can do the following:
1. Declare the xsi namespace in your stylesheet node.
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"

2. If test
Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine1 != ''"/>
  2.   <xsl:value-of 
  3. select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine1"/><br/>
  4. </xsl:if>
Nov 7 '07 #2
jkmyoung
2,057 Recognized Expert Top Contributor
Another possible way is to split out based on the type using a choose-when-otherwise clause. eg:
Expand|Select|Wrap|Line Numbers
  1. <xsl:choose>
  2.   <xsl:when test="@xsi:type='UK'">
  3.      Output UK values here
  4.   </xsl:when>
  5.   <xsl:when test="@xsi:type='US'">
  6.      Output US values here
  7.   </xsl:when>
  8.   <xsl:otherwise>
  9.      Output default values here
  10.   </xsl:otherwise>
  11. </xsl:choose>
  12.  
Nov 7 '07 #3
robtyketto
108 New Member
I've got the testing for empty strings problem solved.

Having issues with the xsi:type

Expand|Select|Wrap|Line Numbers
  1.     <xsl:for-each select="//my:POD/my:Customer">
  2.                                 <xsl:choose>    
  3.                                         <xsl:when test ="@xsi:type='my:UKCustomer'">
  4.                                             <xsl:value-of select="my:CustomerCounty"/><br/>
  5.                                             <xsl:value-of select="my:CustomerPostCode"/><br/>
  6.     </xsl:when>    
  7.                                 </xsl:choose>    
  8.                             </xsl:for-each>
If I remove the choose and when code the data is being retrieved on the match.

I assumed since its selecing all elements under complex type Customer who's xsi:type = "UKCustomer " the xsl:when type will look for the xsi:type of Customer element.

Syntax wise its all right, just no values selected.

Thanks
Rob

XML data again showing the xsi:type :-

Expand|Select|Wrap|Line Numbers
  1. <Customer xsi:type="UKCustomer">
  2.             <CustomerName>Ford Motors</CustomerName>
  3.             <CustomerCode>123456789A</CustomerCode>
  4.             <CustomerAddressLine1>10 Harvard Road</CustomerAddressLine1>
  5.             <CustomerAddressLine2>Fenton</CustomerAddressLine2>
  6.             <CustomerAddressLine3>Stoke-on-Trent</CustomerAddressLine3>
  7.             <CustomerAddressLine4></CustomerAddressLine4>
  8.             <CustomerCountry>United Kingdom</CustomerCountry>
  9.             <CustomerSigneeName>Trevor Thames</CustomerSigneeName>
  10.             <CustomerSigneeSignature>T.Thames</CustomerSigneeSignature>
  11.             <CustomerCounty>Staffordshire</CustomerCounty>
  12.             <CustomerPostCode>ST2 9DS</CustomerPostCode>
  13.         </Customer>
Nov 8 '07 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <xsl:when test ="@xsi:type='my:UKCustomer'">
Expand|Select|Wrap|Line Numbers
  1. <Customer xsi:type="UKCustomer">
Your xsi:type attribute has no my: in front of it.
Could it be as simple as that?
Nov 8 '07 #5
robtyketto
108 New Member
I removed the my: and still runs without retrieving data :-(

I've ruled out a problem with the match as ="//my:POD/my:Customer" will print the elements out if removing the choose and when options.

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="//my:POD/my:Customer">
  2.                                 <xsl:choose>    
  3.                                         <xsl:when test ="@xsi:type='UKCustomer'">
  4.                                             <xsl:value-of select="my:CustomerCounty"/><br/>
  5.                                             <xsl:value-of select="my:CustomerPostCode"/><br/>
  6.                                             </xsl:when>    
  7.                                     </xsl:choose>    
  8.                             </xsl:for-each>
Nov 8 '07 #6
jkmyoung
2,057 Recognized Expert Top Contributor
Only thing that comes to mind is that the xmlns:xsi namespace might be defined slightly differently in each file. Other than that you'd need to post your full xsl and xml to determine why.
Nov 8 '07 #7
robtyketto
108 New Member
Thanks for all the help so far :-)

Here's the full code :-
XML

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <PODBatch xmlns="http://my-pod/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my-pod/namespace POD02.XSD">
  3. <POD>
  4.         <DeliveryInfo>
  5.             <DeliveryNoteNo>DN012345</DeliveryNoteNo>
  6.             <DeliveryDateTime>01/11/07 10:35</DeliveryDateTime>
  7.             <DeliveryDrivername>Bill Egg</DeliveryDrivername>
  8.             <DeliveryDriverSignature>B.Egg</DeliveryDriverSignature>
  9.             <DeliveryStatus>In transit</DeliveryStatus>
  10.         </DeliveryInfo>
  11.         <Customer xsi:type="UKCustomer">
  12.             <CustomerName>Ford Motors</CustomerName>
  13.             <CustomerCode>123456789A</CustomerCode>
  14.             <CustomerAddressLine1>10 Harvard Road</CustomerAddressLine1>
  15.             <CustomerAddressLine2>Fenton</CustomerAddressLine2>
  16.             <CustomerAddressLine3>Stoke-on-Trent</CustomerAddressLine3>
  17.             <CustomerAddressLine4></CustomerAddressLine4>
  18.             <CustomerCountry>United Kingdom</CustomerCountry>
  19.             <CustomerSigneeName>Trevor Thames</CustomerSigneeName>
  20.             <CustomerSigneeSignature>T.Thames</CustomerSigneeSignature>
  21.             <CustomerCounty>Staffordshire</CustomerCounty>
  22.             <CustomerPostCode>ST2 9DS</CustomerPostCode>
  23.         </Customer>
  24.         <OrderDetails>
  25.             <ItemDescription>Radiator Large Type 1</ItemDescription>
  26.             <ItemCustomerRef>RL01</ItemCustomerRef>
  27.             <ItemQty>5</ItemQty>
  28.         </OrderDetails>
  29.         <OrderDetails>
  30.             <ItemDescription>Radiator Small Type 1</ItemDescription>
  31.             <ItemCustomerRef>RS01</ItemCustomerRef>
  32.             <ItemQty>5</ItemQty>
  33.         </OrderDetails>
  34.         <OrderDetails>
  35.             <ItemDescription>Valve</ItemDescription>
  36.             <ItemCustomerRef>Val001</ItemCustomerRef>
  37.             <ItemQty>20</ItemQty>
  38.         </OrderDetails>
  39.     </POD>
  40. </PODBatch>

XSL

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xsi ="http://www.w3.org/2200/10/XMLSchema-instance"
  4. xmlns:my="http://my-pod/namespace">
  5.  
  6. <xsl:template match="/">
  7.     <html>
  8.         <Header>    
  9.             <img src="http://i140.photobucket.com/albums/r13/robtyketto/truck-clipart-icon2_ys61.gif" align="left"/>
  10.         <h1>Proof-of-Delivery</h1>
  11.         <br></br>
  12.  
  13.         <table border ="0" width="880">
  14.             <tr>
  15.                 <td align="left" width="440"><font size="4"><b>Delivery note no: </b><xsl:value-of select="my:PODBatch/my:POD/my:DeliveryInfo/my:DeliveryNoteNo"/></font></td>
  16.                 <td align="left" width="440"><font size="4"><b>Delivery date: </b><xsl:value-of select="substring(my:PODBatch/my:POD/my:DeliveryInfo/my:DeliveryDateTime,1,8)"/>  <b> delivery time: </b><xsl:value-of select="substring(my:PODBatch/my:POD/my:DeliveryInfo/my:DeliveryDateTime,10,5)"/> </font></td>
  17.             </tr>
  18.         </table>
  19.  
  20.         <hr align="left" width="880"></hr>    
  21.  
  22.         </Header>
  23.         <body>
  24.  
  25.         <table border = "0" width="880">
  26.         <tr>
  27.             <td width="400"><b>VAT No: </b>GB7778564</td>
  28.             <td width="400"><b>Customer no: </b><xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerCode"/></td>
  29.         </tr>
  30.         </table>
  31.  
  32.  
  33.             <table border = "1" width="880">
  34.                 <tr bgcolor = "#FFFFFF">
  35.                     <th align="left" width="440">Sender:</th> 
  36.                     <th align="left" width="440">Receiptant:</th> 
  37.                 </tr>
  38.  
  39.                 <tr>
  40.                         <td>Robs Company<br/>
  41.                         Hersham Place<br/>
  42.                         Walton-on-Thames<br/>
  43.                         Surrey<br/>
  44.                         KT19 4ZZ<br/>
  45.                         United Kingdom<br/>
  46.                         <br/>
  47.                         Telephone: 01782 880 8899<br/>
  48.                         E-Mail: westrad@supanet.co.uk
  49.                         </td>    
  50.  
  51.                     <td align="justify" valign="top">
  52.                         <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerName"/><br/>
  53.                         <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine1"/><br/>
  54.                         <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine2"/><br/>
  55.                         <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine3"/><br/>
  56.  
  57.                             <xsl:if test="string-length(my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine4) >0 ">
  58.                                 <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerAddressLine4"/><br/>
  59.                             </xsl:if>
  60.  
  61.                             <xsl:for-each select="//my:POD/my:Customer">
  62.                                 <xsl:choose>    
  63.                                         <xsl:when test ="@xsi:type='UKCustomer'">
  64.                                             <xsl:value-of select="my:CustomerCounty"/><br/>
  65.                                             <xsl:value-of select="my:CustomerPostCode"/><br/>
  66.                                             </xsl:when>    
  67.                                     </xsl:choose>    
  68.                             </xsl:for-each>
  69.  
  70.                             <xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerCountry"/><br/>
  71.                     </td>
  72.                 </tr>        
  73.         </table>
  74.  
  75.         <hr align="left" width="880"></hr>
  76.  
  77.         <table border = "1" width="880" >
  78.             <tr> 
  79.                 <th align="left"><b>Order line</b></th> 
  80.                 <th align="left"><b>Item desc</b></th>
  81.                 <th align="left"><b>Item ref</b></th>
  82.                 <th align="right"><b>Item quantity</b></th> 
  83.             </tr> 
  84.  
  85.             <xsl:for-each select="//my:POD/my:OrderDetails">
  86.                 <tr>
  87.                         <td width="100"><xsl:value-of select="position()"/></td>
  88.                         <td width="325"><xsl:value-of select="my:ItemDescription"/></td>
  89.                         <td><xsl:value-of select="my:ItemCustomerRef"/></td>
  90.                         <td align ="right"><xsl:value-of select="my:ItemQty"/></td>
  91.                 </tr>
  92.             </xsl:for-each>
  93.  
  94.             <tr>
  95.                 <td></td>
  96.                 <td></td>
  97.                 <td><b>Total</b></td>
  98.                 <td align="right"><xsl:value-of select="sum(/my:PODBatch/my:POD/my:OrderDetails/my:ItemQty)"/></td>
  99.             </tr>
  100.  
  101.         </table>
  102.     </body>
  103.  
  104.     <hr align="left" width="880"></hr>
  105.  
  106.     <footer>
  107.         <table border = "0"  width="880">
  108.             <tr>
  109.                     <td width="220"><b>Driver name: </b></td>
  110.                     <td width="220"><xsl:value-of select="my:PODBatch/my:POD/my:DeliveryInfo/my:DeliveryDrivername"/></td>
  111.                     <td width="220"><b>Customer signee name: </b></td>
  112.                     <td width="220"><xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerSigneeName"/></td>
  113.             </tr>
  114.                 <tr>
  115.                     <td><b>Driver signature: </b></td>
  116.                     <td ><xsl:value-of select="my:PODBatch/my:POD/my:DeliveryInfo/my:DeliveryDriverSignature"/></td>
  117.                     <td><b>Customer signature: </b></td>
  118.                     <td><xsl:value-of select="my:PODBatch/my:POD/my:Customer/my:CustomerSigneeSignature"/></td>
  119.             </tr>
  120.         </table>
  121.     </footer>
  122.  
  123. </html>
  124. </xsl:template>
  125.  
  126. </xsl:stylesheet>
Nov 8 '07 #8
jkmyoung
2,057 Recognized Expert Top Contributor
As I thought, the xmlns:xsi namespaces are defined differently.
Should be using
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance
in both instances.
The version in your xslt in incorrect.
Nov 8 '07 #9

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

Similar topics

2
3398
by: Jordan Willms | last post by:
Hi there. I am working with lom metadata and I am a little confused with how to form the following xml element: <lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd"/>
2
7493
by: kaush | last post by:
Hi all, I am trying to serialize a C# object into a XML document using "XmlSerializer" class. One of the elements of the XML document needs a "xsi:schemaLocation" attribute. I am not sure how to add this to the XML element Please help me with if you can. Thanks, kaush
0
1742
by: Dan A | last post by:
I have a SOAP written in Java, and being served by Apache Axis - using the wrapped mode. I then used VS 2003 to generate C# client stubs. I have many complex types that are returned - and these work fine for the most part. The current problem I have (Which appears to be a bug with .NET - but I can't seem to find a place to report .NET bugs without paying money) is that when I call a method that returns an array of one of my own...
0
1391
by: Randall Arnold | last post by:
I have a Microsoft Access report (built on a SQL Server 2000 query) I have exported as xml/html. I include a stylesheet in the original export for formatting of the report. The schema is separate. When I preview this in my Visual web developer Express project it looks almost perfect (VBA generated color formatting is missing, but that's no show-stopper). So it works up to here. For unknown reasons I cannot use the Live Data option in...
1
1682
by: hilz | last post by:
Hi. I have two xml files with the following roots: <MyRootElement xmlns="http://myURI" xmlns:prefixA="http://URI_for_A" xmlns:prefixB="http://URI_for_B" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://myURI http://myURI/mySchema.xsd" prefixA:someAttribute="some value"
3
2054
by: Russ | last post by:
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x 4.54 In other words, if I substitute a class instance for "x" above, I'd like to make the format string apply to an element or elements of the instance. Can I somehow overload the "%" operator for that? Thanks.
16
3515
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which...
1
2486
by: =?Utf-8?B?VG9uZQ==?= | last post by:
Hi, I need to change a value of an element in an XML file, I have been trying to select the node to edit but can only get as far as component and have to itterate through.. XmlDocument doc = new XmlDocument(); doc.Load("C:\\WINDOWS\\Panther\\Sysprep.xml"); // Create an XmlNamespaceManager to resolve the default namespace.
2
12929
by: MedIt | last post by:
Hi, I am new in using xsl.I am stuck in a simple task,which is trying to remove an atribute from a node,and keep the rest of the attributes of this element in the xslt. I have tried a couple of options but to no use so far! Can any one shed some light on me? Here's a sample of my original xml: <?xml version="1.0" encoding="UTF-8" ?> <dom xmlns="http://www.cdisc.org/ns/odm/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"...
1
1507
by: dbuchanan | last post by:
I want to fill a textbox or a label or with lines from a listbox. I want to preserve the lline for line as it comes from the list box. I do not want the test to run-on. I suppose it is okay to wrap if it is longer than the width of the control. This data will later be taken from this control and put into a text box in a report in ReportViewer where I will want to preserve the same formating there. Thank you,
0
8876
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, 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...
1
8556
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8642
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5666
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();...
0
4198
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...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
bsmnconsultancy
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.