Solved

XML/DOM manipulation using ASP or XSLT

Posted on 2013-10-23
8
434 Views
Last Modified: 2014-02-20
I have a request that's similar in functionality to this from 2-2012.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_27598078.html

This time, the XML is formatted differently.

I have this XML file:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getInventoryQtyTransitDaysResponse xmlns:ns2="http://impl.webservice.integration.sanmar.com/">
<return>
<errorOccurred>false</errorOccurred>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XS</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>69</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>


<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>S</size> 
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>


<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>M</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>0</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>L</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XL</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XS</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>268</quantity>
<daysInTransit>2</daysInTransit>
</listResponse>


<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>S</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>2</daysInTransit>
</listResponse>


<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>M</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>2</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>L</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>2</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XL</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>2</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XS</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>4</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>S</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>4</daysInTransit>
</listResponse>

<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>M</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>4</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>L</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>4</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XL</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>4</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XS</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>5</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>S</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>5</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>M</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>5</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>L</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>5</daysInTransit>
</listResponse>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XL</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>5</daysInTransit>
</listResponse>
<message>Request fulfilled successfully</message>
</return>
</ns2:getInventoryQtyTransitDaysResponse>
</S:Body>
</S:Envelope>

Open in new window


I need to output to this table:

Example output
Can I do this with classic ASP (is that possible here) or do I need to use XSLT?

Can anybody help me with this?
0
Comment
Question by:P-Daddy
  • 5
  • 3
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39594407
You have read the discussion in that question.
So you also know my answer:
The code for solving this in XSLT is far more elegant than the code for doing this in straight ASP DOM code, and undoubtly more robust, maintainable and better performing...
but it is a choice you have to make.
(you referencing an old question proves that it is an error to not accept the right answer :-)

If you would be happy with the XSLT approach, I can give it a shot.
0
 

Author Comment

by:P-Daddy
ID: 39594432
Gertone -

You've persuaded me! Can you show me how this would be done using XSLT?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39594498
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:key name="lr-by-size" match="listResponse" use="size"/>
    <xsl:key name="lr-by-days" match="listResponse" use="daysInTransit"/>
    <xsl:key name="lr-by-sizedays" match="listResponse" use="concat(daysInTransit, size)"/>
    
    <xsl:template match="/">
        <table border="1">
            <tr>
                <th></th>
                <xsl:for-each select="//listResponse[generate-id() = generate-id(key('lr-by-size', size)[1])]">
                    <th>
                        <xsl:value-of select="size"/>
                    </th>
                </xsl:for-each>
            </tr>
            <xsl:for-each select="//listResponse[generate-id() = generate-id(key('lr-by-days', daysInTransit)[1])]">
                <xsl:sort select="daysInTransit" data-type="number" order="ascending"/>
                <xsl:variable name="days" select="daysInTransit"/>
                <tr>
                    <th><xsl:value-of select="$days"/></th>
                    <xsl:for-each select="//listResponse[generate-id() = generate-id(key('lr-by-size', size)[1])]">
                        <td>
                            <xsl:value-of select="sum(key('lr-by-sizedays', concat($days, size))/quantity)"/>
                        </td>
                    </xsl:for-each>
                </tr>
            </xsl:for-each>
            
        </table>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39594502
Clear and concise, isn't it?
I admit it requires understanding Muenchian grouping and keys
0
 

Author Comment

by:P-Daddy
ID: 39594526
Thanks!

To run, I would use a method like what you posted here, correct?

<%
Dim objXML
Dim objXSLT
Dim objTpl
Dim objProc

Set objXML = Server.CreateObject("MSXML2.DOMDocument")
objXML.async = False
objXML.load(Server.MapPath("your-xml.xml"))

Set objXSLT = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXSLT.async = False
objXSLT.load(Server.MapPath("your-xsl.xsl"))

Set objTpl = Server.CreateObject("MSXML2.XSLTemplate")
objTpl.stylesheet = objXSLT

Set objProc = objTpl.createProcessor()
objProc.input = objXML
objProc.transform()

Response.Write objProc.output

%>

Open in new window


I'm going to read up on Muenchian grouping and keys.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39594560
That code should work, indeed

this is an interesting article on muenchian
http://jenitennison.com/xslt/grouping/muenchian.html
0
 

Author Comment

by:P-Daddy
ID: 39874059
Hi Geert -

I'm back on this project and have a need to sort the column headers by size. Can this be done using the XSLT method you provided?

Today it's coming back like this:

2XL | 3XL |4XL | 5XL | 6XL |L | M | S | XL | XS

I'd like it to follow this pattern (smallest to largest):

XS | S | M | L | XL | 2XL | 3XL |4XL | 5XL | 6XL

Is that possible?


Current column headers
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39875361
I just posted a solution in your follow up question.
by using the technique of a mapping table, you can force a sort
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javasctipt 2 25
How to hyperlink a document in MS Word w/o full path 1 30
HTML5 frame 5 25
Eliminate additional border 1 18
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question