Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Complicated X Query

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 5/1/2007 10:08:00 PM

Using XSLT 2.0 one possible solution is the following:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 >
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:template match="/">

   <xsl:for-each select="/*/*/order">
     <xsl:sort data-type="number" order="descending" select=
      "max(for $nItems in count(item),
               $i in 1 to $nItems,
               $j in  remove(1 to $nItems, $i)
                 return(item[$i]/@quantity
                       +
                        item[$j]/@quantity)
           )
      "
      />

      <xsl:if test="position() = 1">
        <xsl:for-each select="item">
          <xsl:sort order="descending" select="quantity"/>

          <xsl:if test="position() le 2">
            <xsl:sequence select="."/>
          </xsl:if>
        </xsl:for-each>
      </xsl:if>
   </xsl:for-each>

 </xsl:template>
</xsl:stylesheet>

When applied on the provided source xml document, the result is:

<item product-id="msft30" quantity="6"/>
<item product-id="sam2" quantity="2"/>


Cheers,
Dimitre Novatchev

"Bhavin" <v2desperado@g...> wrote in message 
news:1178076287.582665.124210@y......
>I need to write a complicated  X query. The Query is
> 1] which lists 2 most popular pairs of products bought together.
>
> and XML file is
>
> <e-store>
>   <product id="cre30" name="Creative ZEN VISION"
> price="255.99">Creative White 30GB USB 2.0 ZEN VISION Model
> 70PF115100011 - Retail</product>
>   <product id="ipod30" name="Apple iPod" price="236.99">Apple new
> iPod video Black 30GB Model MA446LL/A - Retail</product>
>   <product id="sam2" name="Samsung Black" price="154.99"> SAMSUNG
> Black 2GB USB 2.0 Audio Player with Built-in Speakers Model YP-K5JQB -
> Retail</product>
>   <product id="tosh60" name="Toshiba Piano Black" price="175.99">
> Recertified: TOSHIBA Piano Black 60GB USB 2.0 Portable Media Player
> Model MES60VK</product>
>   <product id="san4" name="SanDisk Sansa" price="135.99"> SanDisk
> Sansa e260 Black 4GB USB 2.0 MP3 Player Model SDMX44096A70 - Retail</
> product>
>   <product id="msft30" name="Microsoft Zune Black" price="223.99">
> Microsoft Zune Black 30GB Hi-Speed USB, Wi-Fi(802.11 b/g) Large color
> screen Digital media player Model JS8-00001 - Retail</product>
>   <product id="iaud2" name="iAUDIO Black" price="162.99">iAUDIO Black
> 2GB USB 2.0 Portable Video Player Model D2-2048BL - Retail</product>
>   <product id="arch30" name="ARCHOS Silver" price="255.99"> ARCHOS
> Silver 30GB USB 2.0 High-Speed Device (compatible USB 1.1): Mass
> Storage class (MSC) and Media Transport Protocol (MTP)</product>
>   <product id="ipod80" name="Apple iPod video" price="324.99"> Apple
> new iPod video Black 80GB Model MA450LL/A - Retail</product>
>   <product id="ipod2" name="Apple new iPod nano" price="142.99">Apple
> new iPod nano Silver 2GB Model MA477LL/A - Retail</product>
>
>   <warehouse address="NY">
>      <product-item product-id="cre30" quantity="5"/>
>      <product-item product-id="ipod30" quantity="3"/>
>      <product-item product-id="sam2" quantity="3"/>
>      <product-item product-id="tosh60" quantity="2"/>
>      <product-item product-id="san4" quantity="2"/>
>   </warehouse>
>
>   <warehouse address="TX">
>      <product-item product-id="cre30" quantity="5"/>
>      <product-item product-id="sam2" quantity="3"/>
>      <product-item product-id="san4" quantity="20"/>
>      <product-item product-id="msft30" quantity="1"/>
>      <product-item product-id="iaud2" quantity="2"/>
>      <product-item product-id="ipod2" quantity="4"/>
>   </warehouse>
>
>   <client name="John" address="Buffalo, NY">
>      <order order-date="2007-04-15" shipping-date="2007-04-18">
>         <item product-id="cre30" quantity="1"/>
> <item product-id="sam2" quantity="2"/>
> <item product-id="arch30" quantity="1"/>
> <item product-id="ipod80" quantity="4"/>
>      </order>
>      <order order-date="2007-04-15" shipping-date="2007-04-17">
>         <item product-id="cre30" quantity="1"/>
> <item product-id="ipod2" quantity="2"/>
> <item product-id="sam2" quantity="2"/>
>      </order>
>      <order order-date="2007-04-23">
>         <item product-id="msft30" quantity="6"/>
> <item product-id="sam2" quantity="2"/>
> <item product-id="ipod30" quantity="2"/>
>      </order>
>   </client>
>
>   <client name="Larry" address="Albany, NY">
>      <order order-date="2007-04-18" shipping-date="2007-04-20">
>         <item product-id="cre30" quantity="1"/>
> <item product-id="ipod2" quantity="1"/>
> <item product-id="sam2" quantity="1"/>
>      </order>
>      <order order-date="2007-04-18" shipping-date="2007-04-20">
>         <item product-id="sam2" quantity="1"/>
> <item product-id="ipod30" quantity="1"/>
> <item product-id="san4" quantity="1"/>
>      </order>
>      <order order-date="2007-04-22">
>         <item product-id="san4" quantity="1"/>
> <item product-id="sam2" quantity="2"/>
> <item product-id="iaud2" quantity="2"/>
>      </order>
>   </client>
>
>   <client name="Liz" address="Niagara Falls, NY">
>      <order order-date="2007-03-12" shipping-date="2007-03-14">
> <item product-id="san4" quantity="1"/>
> <item product-id="sam2" quantity="1"/>
> <item product-id="arch30" quantity="3"/>
>      </order>
>      <order order-date="2007-04-24">
> <item product-id="iaud2" quantity="1"/>
>      </order>
>   </client>
> </e-store>
>
>
> Actually I am new to X query and it is hard to implement using X Path.
> Any help will be really appreciated .
>
> Regards
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent