Link to home
Start Free TrialLog in
Avatar of oxford100
oxford100

asked on

question for Gertone

Gertone,

Going on my last question, my xml got more complicated.  I got your code to work in the last example, but now things have changed.  

I'm still trying to sort by highest low price first.

Here is my code and xsl.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
 
   <xsl:template match="Auto/Dealer/CarAvailability">
	    <xsl:apply-templates select="Car[CarPlan][not(@gateway = '3')]">
		<xsl:sort select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price &lt; @Price)][not(following-sibling::ModelRate/@Price &lt; @Price)][1]/@Price" data-type="number" order="descending"/>
	    </xsl:apply-templates>
 
	    <xsl:apply-templates select="Car[CarPlan][@gateway = '2']">
		<xsl:sort select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price &lt; @Price)][not(following-sibling::ModelRate/@Price &lt; @Price)][1]/@Price" data-type="number" order="descending"/>
	    </xsl:apply-templates>
 
	    <xsl:apply-templates select="Car[not(CarPlan)]"/>
    </xsl:template>    
 
    <xsl:template match="Car[CarPlan]">
        <p>
            <xsl:text>$</xsl:text>
            <xsl:value-of select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price &lt; @Price)][not(following-sibling::ModelRate/@Price &lt; @Price)][1]/@Price"/>
            <xsl:text> - </xsl:text>
            <xsl:text>$</xsl:text>
            <xsl:value-of select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price &gt; @Price)][not(following-sibling::ModelRate/@Price &gt; @Price)][1]/@Price"/>
        </p>
     </xsl:template>
 
     <xsl:template match="Car[not(CarPlan)]">
        <p>
            <xsl:text>Car type with Car ID </xsl:text>
            <xsl:value-of select="@CarID"/>
            <xsl:text> not available</xsl:text>
        </p>
    </xsl:template>
    
</xsl:stylesheet>
 
------------------------------------------------
 
<?xml version="1.0"?>
<Auto>
	<Dealer>
		<CarAvailability>
			<Car CarID="4444444444"/>
			<Car CarID="11111">
				<CarPlan gateway="3">
                  <Model>
                        <ModelRate  Price="100.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="8000.00"/>
                  </Model>
				</CarPlan>
			</Car>
			<Car CarID="22222">
				 <CarPlan gateway="2">
                  <Model>
                        <ModelRate  Price="300.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
		</CarAvailability>
	</Dealer>
</Auto>

Open in new window

Avatar of oxford100
oxford100

ASKER

Gertone, Here are the results I was trying to get back using the xsl and xml above:

$300.00 - $8000.00
$100.00 - $8000.00

Car type with Car ID 4444444444 not available

I did the gateway wrong in the apply-template above.  Here is the xsl with the my templates the way I was using them.
------------------------------------------

 <xsl:template match="Auto/Dealer/CarAvailability">
          <xsl:apply-templates select="Car[CarPlan][not(@gateway = '3')]">
            <xsl:sort select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price < @Price)][not(following-sibling::ModelRate/@Price < @Price)][1]/@Price" data-type="number" order="descending"/>
          </xsl:apply-templates>

          <xsl:apply-templates select="Car[CarPlan][@gateway = '3']">
            <xsl:sort select="CarPlan/Model/ModelRate[not(preceding-sibling::ModelRate/@Price < @Price)][not(following-sibling::ModelRate/@Price < @Price)][1]/@Price" data-type="number" order="descending"/>
          </xsl:apply-templates>

          <xsl:apply-templates select="Car[not(CarPlan)]"/>
    </xsl:template>    
Avatar of Gertone (Geert Bormans)
a bit tricky,
but I think this is what you want
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
    
    <xsl:template match="Auto/Dealer/CarAvailability">
        <xsl:apply-templates select="Car[CarPlan][not(@gateway = '3')]">
            <xsl:sort select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][1]/ModelRate/@Price" data-type="number" order="descending"/>
        </xsl:apply-templates>
        
        <xsl:apply-templates select="Car[CarPlan][@gateway = '3']">
            <xsl:sort select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][1]/ModelRate/@Price" data-type="number" order="descending"/>
        </xsl:apply-templates>
        
        <xsl:apply-templates select="Car[not(CarPlan)]"/>
    </xsl:template>    
    
    <xsl:template match="Car[CarPlan]">
        <p>
            <xsl:text>$</xsl:text>
            <xsl:value-of select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][1]/ModelRate/@Price"/>
            <xsl:text> - </xsl:text>
            <xsl:text>$</xsl:text>
            <xsl:value-of select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &gt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &gt; ModelRate/@Price)][1]/ModelRate/@Price"/>
        </p>
    </xsl:template>
    
    <xsl:template match="Car[not(CarPlan)]">
        <p>
            <xsl:text>Car type with Car ID </xsl:text>
            <xsl:value-of select="@CarID"/>
            <xsl:text> not available</xsl:text>
        </p>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

That was a lot closer than I got.  I tried adding more info to my xml just to see what would happen, and it seems to be sorting, but not the way it's suppose to I think. I added the xml below.

Here's what my results look like.  What are yours looking like?
$999.00 - $8000.00
$250.00 - $8000.00
$100.00 - $8000.00

Car type with Car ID 4444444444 not available

It's suppose to be...
$999.00 - $8000.00
$100.00 - $8000.00
$250.00 - $8000.00

Car type with Car ID 4444444444 not available

What am I doing wrong?


<?xml version="1.0"?>
<Auto>
	<Dealer>
		<CarAvailability>
			<Car CarID="4444444444"/>
			<Car CarID="11111">
				<CarPlan gateway="3">
                  <Model>
                        <ModelRate  Price="250.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="8000.00"/>
                  </Model>
				</CarPlan>
			</Car>
			<Car CarID="22222">
				 <CarPlan gateway="2">
                  <Model>
                        <ModelRate  Price="100.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
			<Car CarID="3333333">
				 <CarPlan gateway="5">
                  <Model>
                        <ModelRate  Price="999.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate  Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
		</CarAvailability>
	</Dealer>
</Auto>

Open in new window

We were testing th ewrong attributes.
This should be closer to what you need
   <xsl:template match="Auto/Dealer/CarAvailability">
        <xsl:apply-templates select="Car[CarPlan and not(CarPlan/@gateway = '3')]">
            <xsl:sort select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][1]/ModelRate/@Price" data-type="number" order="descending"/>
        </xsl:apply-templates>
        
        <xsl:apply-templates select="Car[CarPlan and CarPlan/@gateway = '3']">
            <xsl:sort select="CarPlan/Model[not(preceding-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)][1]/ModelRate/@Price" data-type="number" order="descending"/>
        </xsl:apply-templates>
        
        <xsl:apply-templates select="Car[not(CarPlan)]"/>
    </xsl:template>    

Open in new window

Gertone,  your xsl is doing exactly what it should be!  I keep adding xml for different situations.  In the new xml below, you'll notice that within the first <Car> tag, I added a new <CarPlan>.  So now the <Car> tag has two <CarPlan>.   I need to get the lowest Price from all the <CarPlan> within each <Car> and then display a range within each <Car> sorted by the highest low Price first to the highest Price.

Hope that makes sense and sorry for making you work for this one.  If you can figure this one out, then I'll be able to close this.

I've attached more xml.
<?xml version="1.0"?>
<Auto>
	<Dealer>
		<CarAvailability>
			<Car CarID="4444444444"/>
			<Car CarID="11111">
				<CarPlan gateway="3">
                  <Model>
                        <ModelRate Price="250.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="8000.00"/>
                  </Model>
				</CarPlan>
				<CarPlan gateway="3">
                  <Model>
                        <ModelRate Price="20.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="100.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="800.00"/>
                  </Model>
				</CarPlan>
			</Car>
			<Car CarID="454545">
				 <CarPlan gateway="3">
                  <Model>
                        <ModelRate Price="777.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
			<Car CarID="22222">
				 <CarPlan gateway="5">
                  <Model>
                        <ModelRate Price="100.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
			<Car CarID="3333333">
				 <CarPlan gateway="3">
                  <Model>
                        <ModelRate Price="999.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="1000.00"/>
                  </Model>
				  <Model>
                        <ModelRate Price="8000.00"/>
                  </Model>
				 </CarPlan>
			</Car>
		</CarAvailability>
	</Dealer>
</Auto>

Open in new window

This is really becoming complex...
how do you execute the XSLT?
Is it feasible to use XSLT2?
(eg Saxon9B is a free processor of very good quality, that can be used in .NET, java and command-line)
It would be a lot simpeler in XSLT2.
If not, can you tell me which processor you are using?
I think I will go for a two step inside your XSLT
Complex is right....  Saxon9B not possible.  I'm not sure if it's possible to use xslt2 or not.   Calling soap and need to stay on track with the path we've been taking using classic asp.  Almost there.
So this is classic ASP, I can the use msxml nodeset,
Will this be big files?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're brilliant!  That worked and thanks again!