• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

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

0
oxford100
Asked:
oxford100
  • 6
  • 5
1 Solution
 
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>    
0
 
Geert BormansCommented:
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

0
 
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Geert BormansCommented:
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

0
 
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

0
 
Geert BormansCommented:
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
0
 
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.
0
 
Geert BormansCommented:
So this is classic ASP, I can the use msxml nodeset,
Will this be big files?
0
 
Geert BormansCommented:
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

0
 
oxford100Author Commented:
You're brilliant!  That worked and thanks again!
0
 
Geert BormansCommented:
welcome
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now