Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple conditions on child node selection

Posted on 2011-03-06
3
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

609 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