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

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

108 100+
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 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 3946
jkmyoung
2,057 Expert 2GB
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 Expert 2GB
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 100+
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 Expert 2GB
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 100+
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 Expert 2GB
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 100+
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 Expert 2GB
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
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"...
2
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...
0
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...
0
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...
1
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"...
3
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...
16
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...
1
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 =...
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.