DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: XSL Question/Problem

  1. #1
    Guest

    XSL Question/Problem


    I get an XML file from a company, so I am stuck with what they give me.

    It is in the form of

    <?xml version="1.0"?>
    <issue>
    <article>
    <subhead>Fiction</subhead>
    <review>
    ...
    </review>
    <subhead>Non Fiction</subhead>
    <review>
    ...
    </review>
    </article>
    </issue>

    I can write an XSLT file that gets all the reviews but don't know how to
    get reviews where subhead="Fiction" only.

    Any suggestions?


  2. #2
    Russell Jones Guest

    Re: XSL Question/Problem

    Chris:

    Here's an XSLT stylesheet that does what you want--as long as the child
    elements of the article element appear in the same order.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xslutput method="html"/>
    <xsl:template match="/">
    <xsl:for-each select="//issue/article/review[preceding-sibling::subhead[1]
    ='Fiction']">
    <!-- your processing here -->
    <xsl:value-of select="."/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    The for-each select statement looks at the first <subhead> nodes that
    precedes each <review> node it and tests to see if the subhead node has a
    value of 'Fiction'. If so, the for-each includes the review node, otherwise
    it doesn't.

    HTH,
    Russell Jones
    Sr. Web Development Editor,
    DevX.com


    <chris@mail.messineo> wrote in message news:3b9fbb26$1@news.devx.com...
    >
    > I get an XML file from a company, so I am stuck with what they give me.
    >
    > It is in the form of
    >
    > <?xml version="1.0"?>
    > <issue>
    > <article>
    > <subhead>Fiction</subhead>
    > <review>
    > ...
    > </review>
    > <subhead>Non Fiction</subhead>
    > <review>
    > ...
    > </review>
    > </article>
    > </issue>
    >
    > I can write an XSLT file that gets all the reviews but don't know how to
    > get reviews where subhead="Fiction" only.
    >
    > Any suggestions?
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center