Jump to content

Proposed XML for XSLT-based templating


MrAdam

Recommended Posts

Hi guys,I'm pretty new to using XSLT for web-page templates. I'm trying to build a very simple stock management application while I learn, and just wondered if somebody could tell me if the XML I have drafted below would work well with an XSLT template or not.

<?xml version="1.0" encoding="UTF-8"?><root>	<orders>		<order id="1" date="2011-05-26 17:20:34">			<items>				<product ref="1" quantity="5" />				<product ref="2" quantity="4" />			</items>		</order>		<!-- and so on... -->	</orders>	<products>		<product id="1">			<title>Product A</title>			<stock>1234</stock>			<stock_ordered>1000</stock_ordered>			<stock_delivery>2011-06-01</stock_delivery>			<stats>				<total_sold>2344</total_sold>				<order_average>32</order_average>			</stats>		</product>		<!-- and so on... -->	</products></root>

So within the root node, there would be two child nodes for Orders and Products. The idea being the Orders node would obviously contain the order data, and the Products node the product data. I wanted to do it this way to prevent duplicating the product data for each order, and use the "ref" attribute in the Orders->Order->Items product elements to link back to the Products->Product ID attribute.Does this seem like a good idea? Or am I way off?Any help greatly appreciated.Thanks

Link to comment
Share on other sites

The official schema and XSLT/XPath 2.0 dateTime format would be "2011-05-26T17:20:34" not "2011-05-26 17:20:34" so you might consider to use that official format as that way you can make use of dateTime arithmetics and formatting functions in XSLT/XPath 2.0 (or with EXSLT in XSLT 1.0).As for the references, processing them with XSLT (even 1.0) is easy with the help of xsl: key and the key function e.g.

<xsl:key name="p-by-id" match="products/product" use="@id"/><xsl:template match="order">  <xsl:variable name="products" select="key('p-by-id', items/product/@ref)"/>  ...</xsl:template>

shows you how to find the product elements belonging to an order element.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...