Solved

XML/DOM manipulation using ASP or XSLT

Posted on 2013-10-23
8
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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. 
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

710 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