XPath expressions having namespaces

Discussion in 'XML' started by gimme_this_gimme_that@yahoo.com, Apr 20, 2005.

  1. Guest

    I have the following xml file and need some tips on xpath queries to
    fetch the data.

    I think I'm not handling namespaces correctly.

    Here is xml file :


    <?xml version="1.0" encoding="UTF-8"?>

    <epi:component build-version="Gold"
    component-id="sss0005style0001"
    component-type="Grids"
    description="Grid that has 3 columns."
    epi-build="105"
    epi-version="7.1"
    major-version="1"
    minor-version="0"
    title="Default Title"
    xmlns:epi="http://www.epicentric.com/deployment">

    <epi:required-component component-id="template0005"
    component-type="Style Types"
    major-version="7"
    minor-version="1"
    />

    <epi:detail>
    <style-info apply-template-header="true"
    description="A description."
    friendly-id="sss_grid.default"
    id="sss0005style0001"
    is-system="false"
    primary-filename="sss-grid-default.jsp"
    processing-type="JSP_BASED"
    template-default="false"
    template-uid="template0005"
    title="SPS Default Grid"
    visible="true"
    />
    </epi:detail>
    </epi:component>


    I've been testing the XPath queries using transforms via xalan. Here is
    the xsl :


    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:epi="http://www.epicentric.com/deployment">

    <xsl:template match="/">
    <xsl:value-of select="//style-info[@description]"/>
    <xsl:value-of select="//epi:component[@build-version]"/>
    </xsl:template>

    </xsl:stylesheet>


    Questions :

    1. <xsl:value-of select="//style-info[@description]"/> doesn't return
    anything.
    What expression returns "A description" ?

    Is there a fully qualified expression returning the same value? Like

    "//epi:component/epi:detail/style-info[@description]".

    2. <xsl:value-of select="//epi:component[@build-version]"/>
    What expression returns "Gold" ?
    , Apr 20, 2005
    #1
    1. Advertising

  2. Romin Guest

    1: //epi:component/epi:detail/style-info[@description]/@description --
    returns "A description".

    2: /epi:component[@build-version]/@build-version - returns "Gold".

    In both the expressions that you have used -- you are searching for the
    XML element that has the specified attribute - which is ok. All you
    need to do is add the remaining part of the expression i.e. the
    attribute value that you want to extract out.
    Romin, Apr 20, 2005
    #2
    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. Jim
    Replies:
    2
    Views:
    447
    Richard Tobin
    Jan 29, 2004
  2. kj
    Replies:
    3
    Views:
    22,574
    sandhya
    Mar 27, 2010
  3. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,622
    Richard Tobin
    Nov 13, 2004
  4. Stefan Franke

    XPath and namespaces...

    Stefan Franke, Jan 2, 2005, in forum: XML
    Replies:
    6
    Views:
    1,074
    Martin Honnen
    Jan 3, 2005
  5. clintonG

    Having problems with namespaces

    clintonG, Apr 2, 2008, in forum: ASP .Net
    Replies:
    6
    Views:
    1,303
    George Ter-Saakov
    Apr 3, 2008
Loading...

Share This Page