Solved

XML/DOM manipulation using ASP or XSLT

Posted on 2013-10-23
8
437 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

680 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