Solved

Multiple conditions on child node selection

Posted on 2011-03-06
3
284 Views
Last Modified: 2013-11-18
Hi Experts,

I need some help formulating an XSL template that will output what I need from the attached XML file.

For each <tsfile> I need to locate the last <p> which has <id>[2] = 0.
Then return all <p>'s after the above position()

I've had a go, but I'm still learning XSLT and not having much luck.

Thanks
<?xml version="1.0" standalone="yes"?>
<h_xml_store>
  <tsfile site="A">
    <variable variable="200.00">
      <p>
        <id>1 Jan</id>
        <id>20</id>
      </p>
      <p>
        <id>2 Jan</id>
        <id>0</id>
      </p>
      <p>
        <id>3 Jan</id>
        <id>1</id>
      </p>
      <p>
        <id>4 Jan</id>
        <id>2</id>
      </p>
      <p>
        <id>5 Jan</id>
        <id>0</id>
      </p>
      <p>
        <id>6 Jan</id>
        <id>1</id>
      </p>
    </variable>
  </tsfile>
  <tsfile site="B">
    <variable variable="200.00">
      <p>
        <id>3 March</id>
        <id>14</id>
      </p>
      <p>
        <id>4 March</id>
        <id>0</id>
      </p>
      <p>
        <id>8 March</id>
        <id>1</id>
      </p>
      <p>
        <id>9 March</id>
        <id>2</id>
      </p>
    </variable>
  </tsfile>
</h_xml_store>

Open in new window

0
Comment
Question by:SlobberyBoxerDog
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 35054032
sounds like you need this
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="variable">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="p[id[2] = 0][not(following-sibling::p[id[2] = 0])]/following-sibling::node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 1

Author Closing Comment

by:SlobberyBoxerDog
ID: 35054924
Thanks Gertone, works perfect.

Can you suggest any good XSLT books for beginners ? I'm a c# coder and I cant get my head out of procedural mode when working on XSLT
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35054935
this one is a very good learning book
http://my.safaribooksonline.com/book/databases/xml/0596000537

the latest edition also covers XSLT2
http://my.safaribooksonline.com/9780596527211
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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…

747 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

14 Experts available now in Live!

Get 1:1 Help Now