XSL select value-of query

Posted on 2008-11-12
Last Modified: 2013-11-18
In the below sample xml, I want to select the Price for all the CDs with type 'Alternative' and release date in 2008. How can I do that?

<xsl:value-of select="Catalog/Items/CD[Type = 'Alternative' AND Details/Release = '2008%' ]/Price "/>





                        	<Title>Coldplay's Album</Title>








                        	<Title>U2's Album</Title>








                     		<Title>FFF's Album</Title>







Open in new window

Question by:dj_user2
    LVL 60

    Expert Comment

    by:Geert Bormans
    <xsl:value-of select="Catalog/Items/CD[Type = 'Alternative' AND starts-with(Details/Release, '2008') ]/Price "/>

    Author Comment

    I get this error message

    Expected token ']' found 'NAME'. Catalog/Items/CD[Type = 'Alternative' -->AND <--starts-with(Details/Release, '2008') ]/Pr...

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:template match="/">
    	<xsl:value-of select="Catalog/Items/CD[Type = 'Alternative' AND starts-with(Details/Release, '2008') ]/Price "/>

    Open in new window

    LVL 60

    Accepted Solution

    sorry, hit by case-sensitivity
      <xsl:value-of select="Catalog/Items/CD[Type = 'Alternative' and starts-with(Details/Release, '2008') ]/Price "/>
    is correct

    Note, that if there are more than one CD with the same properties (not in your example)
    this will result in a concatenated string of all the prices
    so you might want to do something like this

    <xsl:for-each select="Catalog/Items/CD[Type = 'Alternative' and starts-with(Details/Release, '2008') ]">
       <price><xsl:value-of select="Price "/>

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now