Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    U.S. - East Coast
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XSLT Sorted Subset of XML File

    I have a typical newbie question, hope this is the correct forum and that someone can steer me in the right direction.

    I have a large xml file from which I want to select a subset of elements, then sort the file by a few of the elements, and produce a new file. I'm using VB6 and DOM to load and parse the file and am struggling with the XSLT needed to produce the result tree.

    A simplified version of the source tree looks like this:

    <pre><?xml version="1.0" encoding="UTF-16"?>
    <company_data>
    <regions>
    <region name="AMERICAS">
    <countries>
    <country name="Bermuda">
    <companies>
    <company id="ABCD">
    <name>ABCD Company</name>
    <address>
    <addresslines>
    <addressline>1234 Main Street</addressline>
    <addressline>Anyware, USA</addressline>
    </addresslines>
    </address>
    <phones>
    <phone type="main">123-456-7890</phone>
    <phone type="sales">123-456-1111</phone>
    <phone type="support">888-111-1111</phone>
    </phones>
    <web_address>www.myurl.com</web_address>
    </company>
    <company id="EFGH">
    <name>EFGH Company</name>
    <address>
    <addresslines>
    <addressline>4321 Main Street</addressline>
    <addressline>Somewhere, USA</addressline>
    </addresslines>
    </address>
    <phones>
    <phone type="main">123-456-7890</phone>
    <phone type="sales">123-456-1111</phone>
    </phones>
    <web_address>>www.someurl.com</web_address>
    </company>
    </companies>
    </country>
    </countries>
    </region>
    <region name="ASIA">
    <countries>
    <country name="Australia">
    <companies>
    <company id="LLLL">
    <name>LLLL Company</name>
    <address>
    <addresslines>
    <addressline>4 Kingsland</addressline>
    <addressline>Sydney, Australia</addressline>
    </addresslines>
    </address>
    <phones>
    <phone type="main">123-456-7890</phone>
    </phones>
    <web_address>>www.gday.com</web_address>
    </company>
    </companies>
    </country>
    </countries>
    </region>
    </regions>
    </company_data>
    </pre>



    Could someone clue me in as to what XSLT would allow me to have a result tree that
    does NOT include <phone> elements with a "type" attribute of either "sales" or "support" and
    does NOT include any <web_address> elements at all?

    Thank you very much!

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XSLT Sorted Subset of XML File

    Can you post the XSL you currently have?

    You can filter using the select attribute of the for-each function. For example, to filter for sales and support you would do something like:
    <xsl:for-each select="phone[@type='sales'||@type='support']">

    You can avoid web addresses by simply not including them in your XSLT.

    Hope this helps!

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    U.S. - East Coast
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XSLT Sorted Subset of XML File

    Hi Mark,

    I don't really have any usable XSLT -- that's the problem! I'm trying to learn XSLT, the 3 books I have are confusing to me, and I'm having trouble gleaning the correct syntax to do the selects and copy to a new result tree (ultimately, a new xml file).

    I also forgot to mention the desired sort sequence, which is company/@id within country within region.

    I realize this may be asking a lot, but if you could post some xslt that approximates what I'm trying to do I'd greatly appreciate it. Really, what I need is xslt that extracts a subset of elements from a source tree and sorts the selected elements by one or two child elements (or attributes), and produces a new result tree that will be saved as a permanent xml file.

    BTW, congrats on the wedding!

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XSLT Sorted Subset of XML File

    >>congrats on the wedding!

    Thanks, Ethan!

    I'll have to look into this (as time permits). I have always thought of XSLT as a way to view the results of XML (such as in a Web Browser) rather than modifying the actual XML. Perhaps I'm a bit shortsighted on the possibilties of XSL/T.

    Unfortunately, this is one of my weaker areas...

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XSLT Sorted Subset of XML File


  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Location
    U.S. - East Coast
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XSLT Sorted Subset of XML File

    Thanks, Mark. I had actually seen the W3Schools one, and have done similar searches in Google. I just think that the quality of tutorials is generally poor. I haven't found one that starts truly from the beginning, step-by-step (ok, hand-holding!) of what the syntax actually means and how each statement affects the source document.

    Oh well, I'll get it eventually. Thanks for the perseverance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •