Get root attribute values question 2

Discussion in 'XML' started by GIMME, Apr 9, 2004.

  1. GIMME

    GIMME Guest

    If I have

    <root>
    <a some_attr="AAA"/>
    <b><c/></b>
    <b><c/></b>
    <b><c/></b>
    <b><c><d/></c><b>
    <root>

    What expression will fetch the value of AAA when processing
    elements c ?

    Is there an expression that works for both elements c and d ?


    Thanks.
    GIMME, Apr 9, 2004
    #1
    1. Advertising

  2. "GIMME" <> wrote in message
    news:...
    > If I have
    >
    > <root>
    > <a some_attr="AAA"/>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c><d/></c><b>
    > <root>
    >
    > What expression will fetch the value of AAA when processing
    > elements c ?
    >
    > Is there an expression that works for both elements c and d ?


    Not in your case -- you must first have a well-formed xml document.
    Dimitre Novatchev [MVP XML], Apr 9, 2004
    #2
    1. Advertising

  3. GIMME

    GIMME Guest

    This xml should be better ...

    <root>
    <a some_attr="AAA"/>
    <b><c/></b>
    <b><c/></b>
    <b><c/></b>
    <b><c><d/></c><b/>
    <root>

    Is there a way to reference some_attr when processing both c and d
    where the expression is the same for both?


    "Dimitre Novatchev [MVP XML]" <> wrote in message news:<c55rqk$2l2cm8$-berlin.de>...
    > "GIMME" <> wrote in message
    > news:...
    > > If I have
    > >
    > > <root>
    > > <a some_attr="AAA"/>
    > > <b><c/></b>
    > > <b><c/></b>
    > > <b><c/></b>
    > > <b><c><d/></c><b>
    > > <root>
    > >
    > > What expression will fetch the value of AAA when processing
    > > elements c ?
    > >
    > > Is there an expression that works for both elements c and d ?

    >
    > Not in your case -- you must first have a well-formed xml document.
    GIMME, Apr 9, 2004
    #3
  4. Sorry, it's still not a well-formed xml document.


    "GIMME" <> wrote in message
    news:...
    > This xml should be better ...
    >
    > <root>
    > <a some_attr="AAA"/>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c><d/></c><b/>
    > <root>
    >
    > Is there a way to reference some_attr when processing both c and d
    > where the expression is the same for both?
    >
    >
    > "Dimitre Novatchev [MVP XML]" <> wrote in message

    news:<c55rqk$2l2cm8$-berlin.de>...
    > > "GIMME" <> wrote in message
    > > news:...
    > > > If I have
    > > >
    > > > <root>
    > > > <a some_attr="AAA"/>
    > > > <b><c/></b>
    > > > <b><c/></b>
    > > > <b><c/></b>
    > > > <b><c><d/></c><b>
    > > > <root>
    > > >
    > > > What expression will fetch the value of AAA when processing
    > > > elements c ?
    > > >
    > > > Is there an expression that works for both elements c and d ?

    > >
    > > Not in your case -- you must first have a well-formed xml document.
    Dimitre Novatchev [MVP XML], Apr 9, 2004
    #4
  5. GIMME

    GIMME Guest

    hah. hah. hah ...

    <root>
    <a some_attr="AAA"/>
    <b><c/></b>
    <b><c/></b>
    <b><c/></b>
    <b><c><d/></c></b>
    </root>


    "Dimitre Novatchev [MVP XML]" <> wrote in message news:<c56lvf$2nt0ro$-berlin.de>...
    > Sorry, it's still not a well-formed xml document.
    >
    >
    > "GIMME" <> wrote in message
    > news:...
    > > This xml should be better ...
    > >
    > > <root>
    > > <a some_attr="AAA"/>
    > > <b><c/></b>
    > > <b><c/></b>
    > > <b><c/></b>
    > > <b><c><d/></c><b/>
    > > <root>
    > >
    > > Is there a way to reference some_attr when processing both c and d
    > > where the expression is the same for both?
    > >
    > >
    > > "Dimitre Novatchev [MVP XML]" <> wrote in message

    > news:<c55rqk$2l2cm8$-berlin.de>...
    > > > "GIMME" <> wrote in message
    > > > news:...
    > > > > If I have
    > > > >
    > > > > <root>
    > > > > <a some_attr="AAA"/>
    > > > > <b><c/></b>
    > > > > <b><c/></b>
    > > > > <b><c/></b>
    > > > > <b><c><d/></c><b>
    > > > > <root>
    > > > >
    > > > > What expression will fetch the value of AAA when processing
    > > > > elements c ?
    > > > >
    > > > > Is there an expression that works for both elements c and d ?
    > > >
    > > > Not in your case -- you must first have a well-formed xml document.
    GIMME, Apr 9, 2004
    #5
  6. GIMME

    Gadrin77 Guest

    Assuming that using this well-formed XML:

    <root>
    <a some_attr="AAA"/>
    <b>
    <c/>
    </b>
    <b>
    <c/>
    </b>
    <b>
    <c/>
    </b>
    <b>
    <c>
    <d/>
    </c>
    </b>
    </root>

    this stylesheet/template seems to find the attribute value
    and output it to the screen when I look for the "d" element...

    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="//d">


    <xsl:for-each select="preceding::node()">
    <h4><xsl:value-of select="attribute::*"/></h4>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>
    Gadrin77, Apr 10, 2004
    #6
  7. Use:

    preceding::a[1]/@some_attr


    Cheers,

    Dimitre Novatchev [XML MVP],
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


    "GIMME" <> wrote in message
    news:...
    > hah. hah. hah ...
    >
    > <root>
    > <a some_attr="AAA"/>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c/></b>
    > <b><c><d/></c></b>
    > </root>
    >
    >
    > "Dimitre Novatchev [MVP XML]" <> wrote in message

    news:<c56lvf$2nt0ro$-berlin.de>...
    > > Sorry, it's still not a well-formed xml document.
    > >
    > >
    > > "GIMME" <> wrote in message
    > > news:...
    > > > This xml should be better ...
    > > >
    > > > <root>
    > > > <a some_attr="AAA"/>
    > > > <b><c/></b>
    > > > <b><c/></b>
    > > > <b><c/></b>
    > > > <b><c><d/></c><b/>
    > > > <root>
    > > >
    > > > Is there a way to reference some_attr when processing both c and d
    > > > where the expression is the same for both?
    > > >
    > > >
    > > > "Dimitre Novatchev [MVP XML]" <> wrote in message

    > > news:<c55rqk$2l2cm8$-berlin.de>...
    > > > > "GIMME" <> wrote in message
    > > > > news:...
    > > > > > If I have
    > > > > >
    > > > > > <root>
    > > > > > <a some_attr="AAA"/>
    > > > > > <b><c/></b>
    > > > > > <b><c/></b>
    > > > > > <b><c/></b>
    > > > > > <b><c><d/></c><b>
    > > > > > <root>
    > > > > >
    > > > > > What expression will fetch the value of AAA when processing
    > > > > > elements c ?
    > > > > >
    > > > > > Is there an expression that works for both elements c and d ?
    > > > >
    > > > > Not in your case -- you must first have a well-formed xml document.
    Dimitre Novatchev [MVP XML], Apr 10, 2004
    #7
  8. GIMME

    Gadrin77 Guest

    "Dimitre Novatchev [MVP XML]" <> wrote in message news:<c589of$2os176$-berlin.de>...
    > Use:
    >
    > preceding::a[1]/@some_attr
    >
    >
    > Cheers,
    >
    > Dimitre Novatchev [XML MVP],



    One line, sweet!
    Gadrin77, Apr 10, 2004
    #8
  9. GIMME

    Guest

    asdfasd
    , Jan 10, 2005
    #9
    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. Replies:
    0
    Views:
    1,202
  2. Rick Osborn
    Replies:
    10
    Views:
    3,939
    Jon A. Cruz
    Feb 8, 2004
  3. GIMME

    Get root attribute values

    GIMME, Apr 9, 2004, in forum: XML
    Replies:
    3
    Views:
    361
    Patrick TJ McPhee
    Apr 12, 2004
  4. hector
    Replies:
    5
    Views:
    398
    CBFalconer
    Dec 5, 2006
  5. pbd22
    Replies:
    1
    Views:
    162
    Martin Honnen
    Jul 3, 2007
Loading...

Share This Page