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

oxford100Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oxford100Author Commented:
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>    
Gertone (Geert Bormans)Information ArchitectCommented:
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

oxford100Author Commented:
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

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Gertone (Geert Bormans)Information ArchitectCommented:
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

oxford100Author Commented:
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

Gertone (Geert Bormans)Information ArchitectCommented:
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
oxford100Author Commented:
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.
Gertone (Geert Bormans)Information ArchitectCommented:
So this is classic ASP, I can the use msxml nodeset,
Will this be big files?
Gertone (Geert Bormans)Information ArchitectCommented:
There is no XSLT2 processor that can be used in classic ASP by the way,
I got this working (please test)
But please, don't make it any more complex  :-)
<?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 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) and 
                                                                        not(parent::CarPlan/preceding-sibling::CarPlan/Model/ModelRate/@Price &lt; ModelRate/@Price)]
                                                                       [not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price) and 
                                                                       not(parent::CarPlan/following-sibling::CarPlan/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) and 
                not(parent::CarPlan/preceding-sibling::CarPlan/Model/ModelRate/@Price &lt; ModelRate/@Price)]
                [not(following-sibling::Model/ModelRate/@Price &lt; ModelRate/@Price)and 
                not(parent::CarPlan/following-sibling::CarPlan/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) and 
                not(parent::CarPlan/preceding-sibling::CarPlan/Model/ModelRate/@Price &gt; ModelRate/@Price)]
                [not(following-sibling::Model/ModelRate/@Price &gt; ModelRate/@Price)and 
                not(parent::CarPlan/following-sibling::CarPlan/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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oxford100Author Commented:
You're brilliant!  That worked and thanks again!
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.