Sorry, I don't know how to ask the question. I have 3 xml doc. I have an xsl that is working except for I can't figure out how the total of the price times the quantity. I'm running out of time. Please help... Here is the xsl---
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" doctype-system="about:legacy-compat" encoding="UTF-8" indent="yes" />
<xsl:variable name = "custIn" select = "document('cust.xml')" />
<xsl:variable name = "prodIn" select = "document('prod.xml')" />
<xsl:key name="custN" match="customer" use="@custID" />
<xsl:key name="prodN" match="product" use="@prodID" />
<xsl:template match="/orders">
<html>
<head>
<title>Order List</title>
<link href="cust.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<h1>
<img src = "logo.png" alt="My Things" /></h1>
<h2>Our Orders</h2>
<table id="orderTable">
<tr>
<th>Order Num</th>
<th>Cust</th>
<th>Gr</th>
<th>Product</th>
<th>Price</th>
<th>Qty</th>
<th>Total Cost</th>
<th>Order Date</th>
</tr>
<xsl:for-each select = "order">
<xsl:sort select="orderDate" />
<tr>
<td><xsl:value-of select="@orderID" /></td>
<td>
<xsl:variable name="cID" select="@custID" />
<xsl:for-each select="$custIn">
<xsl:value-of select = "key('custN', $cID)/concat(first_name, ' ', last_name)" />
</xsl:for-each></td>
<td><xsl:value-of select="prodGrp"/></td>
<xsl:variable name="pID" select="@prodID" />
<xsl:for-each select="$prodIn">
<td><xsl:value-of select="key('prodN', $pID)/prodName" /></td>
<td><xsl:value-of select="key('prodN', $pID)/format-number(prodPrice, '$###,##0.00')" /></td>
</xsl:for-each>
<td><xsl:value-of select="prodQty"/></td>
<!-- can't calculate the total for the orders, need the price for each from the products.xml
--can bring in the price each her <xsl:value-of select="key('prodN', $pID)/format-number(prodPrice, '$###,##0.00')"
but has to be multiplied by the prodQty from the orders.xml -->
<td><xsl:value-of select="format-number(prodQty * 5, '$###,##0.00')" />
</td>
<td><xsl:value-of select="format-date(orderDate,'[M01]/[D01]/[Y0001]')" /></td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
--ord.xml example
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order orderID = "ord10007" custID = "cust100030" prodID = "prod001" >
<orderDate>2017-02-02</orderDate>
<prodGrp>pencil</prodGrp>
<prodQty>6</prodQty>
</order>
<order orderID = "ord10020" custID = "cust100031" prodID = "prod010" >
<orderDate>2017-03-03</orderDate>
<prodGrp>pen</prodGrp>
<prodQty>4</prodQty>
</order>
<order orderID = "ord10050" custID = "cust10030" prodID = "prod010" >
<orderDate>2017-04-04</orderDate>
<prodGrp>pen</prodGrp>
<prodQty>7</prodQty>
</order>
<orders>
---prod.xml
<?xml version="1.0" encoding="UTF-8"?>
<list>
<product prodID="prod001">
<prodGrp>pencil</prodGrp>
<prodName>green</prodName>
<description>write nice</description>
<prodPrice>4.95</prodPrice>
<date>2017-02-02</date>
<images>
<img src="pencil.jpg"/>
</images>
</product>
<product prodID="prod010">
<prodGrp>pen</prodGrp>
<prodName>thick pen</prodName>
<description>easy to grip</description>
<prodPrice>.95</prodPrice>
<date>2017-01-01</date>
<images>
<img src="pen.jpg"/>
</images>
</product>
</list>
Need 4 from order times 4.95 from product. Thank you in advance...
If you're using XSLT 2.0, then you can use key directly on another document without having to switch the context to it first, like you're doing now.
Here's a simplified example. This is assuming
ord.xml
is the input document for the XSLT transformation.XSLT 2.0
Using your input example, alongside the
prod.xml
file, you should see a result like this: