XML | Vortx Live Wire Blog

All XML Articles

Coder’s Corner – Extension Data Expanded to XML

Tuesday, February 17th, 2009
In an earlier post, we talked about using the Extension Data field as extra storage space for additional product information. But what if you need a more organized version of that information, in a hierarchy of sorts? Most of the time, that would mean adding an additional table to the database, and adding an additional field in the Admin site so users can store that information. This can be tricky to do, and may also take your site off the upgrade path. Fortunately, we've got a great way to store extensible structured data in the ExtensionData field, but there’s no way to directly manipulate and query text in XSL. This tutorial will show you a quick way to get that extension data out as pure transformable XML. Before reading on, you should already be familiar with XML Packages, and have a basic knowledge of SQL. The Query Let’s select a Product ID and it’s Extension Data: select Product.ProductID, CONVERT(xml, ExtensionData) as ExtensionData from Product for xml path('Product') There are three important things to note here:
  1. CONVERT(xml, ExtensionData) - This reads the text in the ExtensionData field in as an XML fragment instead of text full of “>” and “<”. Be careful, as malformed XML will cause your query to explode!
  2. as ExtensionData - This adds the <ExtensionData> node, with the contents just below.
  3. for xml path('Product') - This outputs the results as an XML document instead of a set of rows and columns. Each row becomes a <Product> element (as we specified with the path(‘Product’) call), and each column becomes a child element.
The XML Package You’ll have to make one tiny change in your XML Package <query name="ExtensionData" rowElementName="Product" retType="xml"> See that retType attribute? That tells AspDotNetStorefront to expect XML data and use it as-is in the runtime document. The Results So, what’s all this get us? Well, if I were to type the following into the ExtensionData field of a product called “Blades”: extensiondata casesize 8 Then the XML for my XML Package comes out like this: extensiondata productID Now I can use the following in my XSLT: Add a case of <xsl:value-of select="/ExtensionData/CaseSize" /> to your cart And it will work as advertised!

Coder’s Corner – Extension Data, ADNSF’s Swiss Army Knife

Wednesday, January 28th, 2009
Out of the box, the Extension Data field isn't used for anything, and the Xml packages don't use this field unless you customize it in, so you may be wondering 'what does it do?' The quick answer? Anything you want it to! This tutorial will show you how to use the Extension Data field to add additional information to your product detail pages. To complete this tutorial, you need access to your site's Xml Packages folder, and a basic knowledge of HTML. You can find the Extension Data field in Products and Categories in AspDotNetStorefront. You may have seen the tab in your product screen admin section over to the far right. Next to the field it says: '(User Defined Data)', which is exactly what it is, extra data as defined by you. You can use this extra field to add and display any additional product-specific information. If you'd like to notify your customers when an item will ship, and that shipping time-frame will vary per product, you can enter the text to display in the Extension Data field, and with a minor customization you can add that to the page. This field can be a lifesaver if you have any other extra details about the product you'd like to add and you've already used your spec sheet field. The Extension Data field is a great tool for us as developers. With Extension Data, we can easily add extra data to the page without having to modify the database schema, or source code, so we've been able to modify the product and category display with Extension Data without taking sites off the upgrade path. If you're new to Xml Packages, XSLT, or AspDotNetStorefront customizations, this is a great place to get started.
  1. Log in to the admin section of your site.
  2. Navigate to a product you'd like to add extra information to through the tree menu under Organization > Manage Categories.
  3. Click on the Extension Data tab to the far right.
  4. In the first field: 'Extension Data (User Defined Data)', enter the information you'd like to appear on the product detail page.
Now that we have data to work with, we can add the extension data field to the Xml Package. Navigate to your site's Xml Packages folder, and locate the Xml Package that is used for that product. If you're not sure which one is being used, go back to admin and go to the main screen of that product. Under the first tab, there is a Display Format Xml Package dropdown menu. The Xml Package selected in that menu is the one being used for that product. Find that file name in your XmlPackages folder, and open it in your favorite text editor. After the file is open, search for the text "<xsl:template match="Product">". Xml packages use these 'template' tags to start a new piece of the template. For instance, in an Xml Package using variants, you'll probably find a 'template match="/"', which is the first template used when the page is loaded. In that template tag, you'll probably see a call to another template called '/root/Products/Product', which is the Product display template, and in there you might find another call to another template called '/root/Variants/Variant'. These are all different pieces of the template that contain different code that is used to control the display format of your product detail page. Each of these template pieces has a different structure of data beneath it, so you'll be able to access different parts of the product display. The Extension Data field is located under /root/Products/Product, so we'll want to find that template and add our Extension Data field there. You can add this field anywhere you like. You'll notice a lot of HTML tags like tables and divs, that will help you locate the correct place to display your Extension Data. Treat this document like a standard HTML page. The structure is similar, so if you want your Extension Data underneath your product description, search for 'description' in your document within the Product template. You'll probably find '$pDescription', this is where it's writing out the description content that you enter in admin. You can add a line break beneath that and add your extension data tag. Once you've found the correct location for your Extension Data field, you can easily place the tag by typing out the following: <xsl:value-of select="ExtensionData" disable-output-escaping="yes"> This is using a simple value-of XSLT element. We're displaying the 'value of' the Extension Data field. The second part of the tag: 'disable-output-escaping' is equally important. When set to yes, all of your HTML tags entered in to your Extension Data field will be 'escaped'. This way, if you'd like to add a line break with the HTML tag <br /> directly in the Extension Data field, it will be added to the code of the page instead of actually written out on the page itself. That's it! After you've added your Extension Data field to your Xml Package and saved your file, you should see your text showing up on your product detail page where it was entered. You may need to refresh your browser in order to see the change. What do you use the Extension Data field for on your site?  Share your experience with the community by leaving a comment below.