Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML newbie (for each)

From: Peter Flynn <peter.no-sp@-.--------.-->
To: NULL
Date: 4/1/2005 11:07:00 PM
Larry wrote:

> Hello everybody,
> 
>                I am really getting into XML and XSL as well.
> Unfortunately I'm still a newbie and would need you guys to tell me how
> to go about parsing this file:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <collection>
>  <cd>
>   <title>Fight for your mind</title>
>   <artist>Ben Harper</artist>
>   <year>1995</year>
>  </cd>
>  <cd>
>   <title>Electric Ladyland</title>
>   <artist>Jimi Hendrix</artist>
>   <year>1997</year>
>  </cd>
>  <cd>
>   <title>Rubber Soul</title>
>   <artist>The Beatles</artist>
>   <year>1965</year>
>  </cd>
>  <cd>
>   <title>Revolver</title>
>   <artist>The Beatles</artist>
>   <year>1966</year>
>  </cd>
>  <cd>
>   <title>White Album</title>
>   <artist>The Beatles</artist>
>   <year>1966</year>
>  </cd>
> </collection>
> 
> I'd like (by using XSLT) to have a response xml file like this:
> 
> <collection>
>  <cd>
>   <title>Revolver</title>
>   <artist>The Beatles</artist>
>   <year>1966</year>
>  </cd>
>  <cd>
>   <title>White Album</title>
>   <artist>The Beatles</artist>
>   <year>1966</year>
>  </cd>
> </collection>
> 
> I read up on XSL and found that I might go about parsing my catalog.xml
> file as follow:

As a general principle, don't use xsl:for-each for processing stuff you want
handled in document order. Keep it for stuff you want to sort, or stuff
that needs handling out of order. Just use templates for normal processing.

If you really just want to output absolute subsets of the markup (ie not
changing anything about each entry), all you need is:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <collection>
      <xsl:copy-of select="collection/cd[contains(artist,'The Beatles') 
                           and year='1966']"/>
    </collection>
  </xsl:template>
  
</xsl:stylesheet>

///Peter
-- 
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"


transparent
Print
Mail
Digg
delicious
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