Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XSLT and XML Nodes

Options
  • 30-01-2006 2:50pm
    #1
    Closed Accounts Posts: 658 ✭✭✭


    Hi

    I'm having a bit of bother selecting the contents of a particular node from an XML file using my XSLT file to process it. Here is an explanation of what I need to do

    Imagine this is the XML file here

    ====================================
    [HTML]
    <feed version="0.3" xml:lang="en" xmlns="http://url.org/atom/ns#&quot; xmlns:aj="http://url.company.com/_atom/aj#"&gt;

    <!-- I want to be able to access entry -->

    <entry xmlns="http://purl.org/atom/ns#&quot; xmlns:aj="http://journals.aol.com/_atom/aj#"&gt;
    <!-- There are things in here I want to access -->
    </entry>
    </feed>
    [/HTML]

    Basically, when I run my XSL file on this XML, it looks at entry and then ignores it, even though I want it to delve in there and work on it. Here is some example XSL code

    <xsl:template match="/">
    <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="entry">
    <!-- do things in here -->
    </xsl:template>

    Does anyone here have any ideas as to what I can do ? I am using XSL 2.0 and XPATH expressions


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    if I understand you correctly all you want to do is extract the values from the entry node? if so the template below should work ( I have tested and it does work). Now I don't know your XML schema but I 'm not sure I like what I've seen. The top level <feed> is ok but if you will be having more than one <entry> in the <feed> then you need to have a <entrys> with each <entry> inside of that.
    I would be interested in seeing your whole XML schems if you didn't mind
    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <xsl:for-each select="//entry">
    <xsl:apply-templates select="."/>
    </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="entry">
    <!--do things in here-->
    </xsl:template>
    


  • Closed Accounts Posts: 658 ✭✭✭pontovic


    I'd show you everything but as its work sensitive information I would probably be fired out of a cannon if I posted the XML file up here. Just tried what you suggested and still no luck unfortunately. Thanks for the reply anyway.


  • Registered Users Posts: 2,781 ✭✭✭amen


    so what exactly is not working? Do you get any errors
    are you calling this from vb/asp/java etc
    is this in browser or in code
    how do you create your XML object and how do you apply the xsl
    I'll give you all the help I can but I need more information


  • Closed Accounts Posts: 658 ✭✭✭pontovic


    Basically after a little experimentation, the problem lies in the fact that them annoying attributes are in the XML nodes, thus making my XSL ignore them, so this doesn't work at all. But...

    ============================

    <feed version="0.3" xml:lang="en" xmlns="http://url.org/atom/ns#&quot; xmlns:aj="http://url.company.com/_atom/aj#"&gt;

    ============================

    This will work

    ============================

    <feed sample_attribute="sample_value" other_attribute="another_value">

    ============================

    I took the two nodes that were being overlooked and made the changes so they looked more like the latter, and things worked perfectly. Anyone here know how to remobe them namespace things or make XSL look at them ? I cannot change the XML file it comes from a particular source who want to keep it the way it is currently, altough if I had the power I would make some changes.


  • Closed Accounts Posts: 658 ✭✭✭pontovic


    Please there must be someone out there who knows something ? I have tried searching on google for this and I cannot find a straight answer. Any ideas ?


  • Advertisement
  • Closed Accounts Posts: 658 ✭✭✭pontovic


    amen wrote:
    so what exactly is not working? Do you get any errors
    are you calling this from vb/asp/java etc
    is this in browser or in code
    how do you create your XML object and how do you apply the xsl
    I'll give you all the help I can but I need more information

    Sorry amen didnt see that post until this morning.

    Basically I have a java app written by someone else in here that takes in an xml file and an xsl file and produces a custom file. Thats all I can say without breaking confidentiality. See 3rd last post above to see whats not working. Basically, if there is a node specified like this in my source XML file
    [HTML]
    <entry xmlns="http://purl.org/atom/ns#&quot; xmlns:aj="http://journals.company.com/_atom/aj#"&gt;
    <!-- there is info in here I access -->
    </entry>

    and in my XSL file there is

    <xsl template match="entry">
    If my XSL parser recognised the entry node, I could read this text, but I can't.
    <!-- do things in here using xsl code to things in the entry node in the xml -->
    </xsl:template>

    [/HTML]

    I have tried loads of things and I can't figure it out. I am pretty new to XSL but I have picked up alot over the last few weeks. I have no choice on how the XML looks or its syntax, as we get it in from another crowd. It is valid XML


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    pontovic wrote:
    <xsl:template match="/">
    <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="entry">
    <!-- do things in here -->
    </xsl:template>
    The first template will get triggered when the parser arrives at the root of the document. The <xsl:apply-templates/> will then work with the default select value of "*", finding those nodes that are immediate children of the document root (feed).

    There is no template for feed.

    You need to either add a new template:

    <xsl:template match="feed">
    <xsl:apply-templates/>
    </xsl:template>

    or else change the first template to jump strait to entry nodes:
    <xsl:template match="/">
    <xsl:apply-templates select="feed/entry"/>
    </xsl:template>


Advertisement