<Orders>
<Order>
<CustomerID>VK</CustomerID>
<Customer>
<CompanyName>Vins et alcools Chevalier</CompanyName>
<Country>France</Country>
<CustomerID>VINET</CustomerID>
<City>Reims</City>
<ContactName>Paul Henriot</ContactName>
<ContactTitle>Accounting Manager</ContactTitle>
</Customer>
<ShipCountry>France</ShipCountry>
<OrderID>10248</OrderID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00.000</OrderDate>
</Order>
</Orders>
The input I am providing is above and need the below output. what changes should i make to the XSLT code to get ot the output. like the value of select statements
Output
<Orders>
<Order>
<CustomerID>VINET</CustomerID>
<CompanyName>Vins et alcools Chevalier</CompanyName>
<Country>France</Country>
<CustomerID>VINET</CustomerID>
<City>Reims</City>
<ContactName>Paul Henriot</ContactName>
<ContactTitle>Accounting Manager</ContactTitle>
<ShipCountry>France</ShipCountry>
<OrderID>10248</OrderID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00.000</OrderDate>
</Order>
</Orders>
My current XSLT style sheet is incorrect and it is added below. Needing the correct stylesheet code. to get the above output. Pls check the below stylesheet and see what changes need to be made.
How to correctly use the value of select statement for the result
xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>All Orders</h2>
<table border="1">
<tr bgcolor="#003333">
<xsl:comment>green</xsl:comment>
<th>CUSTOMERID</th>
<th>SHIPCOUNTRY</th>
<th>ORDERID</th>
<th>EMPLOYEEID</th>
<th>COMPANYNAME</th>
<th>COUNTRY</th>
<th>SHIPCOUNTRY</th>
<th>CITY</th>
<th>CONTACTTITLE</th>
<th>ORDERDATE</th>
</tr>
<xsl:for-each select="Orders/Order">
<xsl:sort select="OrderID"/>
<tr>
<td><xsl:value-of select="CustomerID"/></td>
<td><xsl:value-of select="ShipCountry"/></td>
<td><xsl:value-of select="OrderID"/></td>
<td><xsl:value-of select="EmployeeID"/></td>
<td><xsl:value-of select="CompanyName"/></td>
<td><xsl:value-of select="Country"/></td>
<td><xsl:value-of select="ShipCountry"/></td>
<td><xsl:value-of select="City"/></td>
<td><xsl:value-of select="ContactTitle"/></td>
<td><xsl:value-of select="OrderDate"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Kas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
Please try the following XSLT that is using a so called Identity Transform pattern.
Input XML
<Orders>
<Order>
<CustomerID>VK</CustomerID>
<Customer>
<CompanyName>Vins et alcools Chevalier</CompanyName>
<Country>France</Country>
<CustomerID>VINET</CustomerID>
<City>Reims</City>
<ContactName>Paul Henriot</ContactName>
<ContactTitle>Accounting Manager</ContactTitle>
</Customer>
<ShipCountry>France</ShipCountry>
<OrderID>10248</OrderID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00.000</OrderDate>
</Order>
</Orders>
XSLT
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8"
omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<!--Identity Transform pattern-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Customer">
<xsl:copy-of select="*"/>
</xsl:template>
</xsl:stylesheet>
Output XML
<Orders>
<Order>
<CustomerID>VK</CustomerID>
<CompanyName>Vins et alcools Chevalier</CompanyName>
<Country>France</Country>
<CustomerID>VINET</CustomerID>
<City>Reims</City>
<ContactName>Paul Henriot</ContactName>
<ContactTitle>Accounting Manager</ContactTitle>
<ShipCountry>France</ShipCountry>
<OrderID>10248</OrderID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00.000</OrderDate>
</Order>
</Orders>