XML to XML Filtering using XSL Problem

Discussion in 'XML' started by generalr, Apr 20, 2010.

  1. generalr

    generalr

    Joined:
    Apr 20, 2010
    Messages:
    1
    Guys,

    I know this is a XML NG, but I figured XSL would be allowed here as they are closely related.

    I am trying to filter out XML flows based on using an if statement for an attribute of the root element of the file. For some reason, when I use the following XSLT code with the following XML File, it seems the if statement is never seen, and the XML file is always sent through.

    Do you guys have any ideas on why this is? I have scoured the internet reading how-to's and examples, but still cannot get this to work. 7 hours later, I am still not sure what I am doing wrong.

    The following XML File is simplified for simplicity here.

    TIA,
    David


    Code:
    XML File:
    
    <CarModel Year=2009>
    <A>
     <B>
     <B>
    </A>
    </CarModel>
    
    
    
    XSL File:
    
    <?xml version='1.0' encoding="ISO-8859-1"?>
     <xsl:stylesheet
                     xmlns:xsl="http: ww w3 org 1999 XSL Transform"
                     version="2.0">
    
    <xsl:template match="/CarModel">
      <xsl:if test="@Year=2009"> <xsl:apply-templates select="A"/> </xsl:if>
    
    </xsl:template>
    
    <xsl:template match="A">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>
    PS - the namespace for the XSL is accurate, I had to remove it here as it is considered a link.

    Again, what I am trying to do is only pass through XML Files that have a Year attribute equal to 2009. Once it finds one with 2009, it should copy over the XML file exactly as it was input. Otherwise, I want nothing to pass through.

    Many many thanks to whomever can spare a few minutes to tell me what I'm doing wrong. It has to be something trivial.
    generalr, Apr 20, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Corey
    Replies:
    4
    Views:
    6,814
    Corey
    Feb 16, 2005
  2. schaf@2wire.ch
    Replies:
    1
    Views:
    3,591
    A. Bolmarcich
    May 27, 2005
  3. sai krishna

    xsl dynamic filtering

    sai krishna, Jun 5, 2006, in forum: XML
    Replies:
    1
    Views:
    918
    Martin Honnen
    Jun 5, 2006
  4. jobooker@gmail.com

    xsl:sort using an xsl:variable as the sort key

    jobooker@gmail.com, Sep 5, 2006, in forum: XML
    Replies:
    2
    Views:
    9,247
    Martin Honnen
    Sep 5, 2006
  5. itssri.srinivas@gmail.com
    Replies:
    1
    Views:
    483
    Joseph Kesselman
    Nov 5, 2007
Loading...

Share This Page