Get root attribute values question 2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GIMME

    Get root attribute values question 2

    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.
  • Dimitre Novatchev  [MVP XML]

    #2
    Re: Get root attribute values question 2


    "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
    news:3f12b4fb.0 404081703.39989 dd0@posting.goo gle.com...[color=blue]
    > 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 ?[/color]

    Not in your case -- you must first have a well-formed xml document.



    Comment

    • GIMME

      #3
      Re: Get root attribute values question 2

      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]" <dnovatchev@yah oo.com> wrote in message news:<c55rqk$2l 2cm8$1@ID-152440.news.uni-berlin.de>...[color=blue]
      > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
      > news:3f12b4fb.0 404081703.39989 dd0@posting.goo gle.com...[color=green]
      > > 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 ?[/color]
      >
      > Not in your case -- you must first have a well-formed xml document.[/color]

      Comment

      • Dimitre Novatchev  [MVP XML]

        #4
        Re: Get root attribute values question 2

        Sorry, it's still not a well-formed xml document.


        "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
        news:3f12b4fb.0 404090835.2a667 616@posting.goo gle.com...[color=blue]
        > 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]" <dnovatchev@yah oo.com> wrote in message[/color]
        news:<c55rqk$2l 2cm8$1@ID-152440.news.uni-berlin.de>...[color=blue][color=green]
        > > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
        > > news:3f12b4fb.0 404081703.39989 dd0@posting.goo gle.com...[color=darkred]
        > > > 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 ?[/color]
        > >
        > > Not in your case -- you must first have a well-formed xml document.[/color][/color]


        Comment

        • GIMME

          #5
          Re: Get root attribute values question 2

          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]" <dnovatchev@yah oo.com> wrote in message news:<c56lvf$2n t0ro$1@ID-152440.news.uni-berlin.de>...[color=blue]
          > Sorry, it's still not a well-formed xml document.
          >
          >
          > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
          > news:3f12b4fb.0 404090835.2a667 616@posting.goo gle.com...[color=green]
          > > 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]" <dnovatchev@yah oo.com> wrote in message[/color]
          > news:<c55rqk$2l 2cm8$1@ID-152440.news.uni-berlin.de>...[color=green][color=darkred]
          > > > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
          > > > news:3f12b4fb.0 404081703.39989 dd0@posting.goo gle.com...
          > > > > 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.[/color][/color][/color]

          Comment

          • Gadrin77

            #6
            Re: Get root attribute values question 2

            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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">

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


            <xsl:for-each select="precedi ng::node()">
            <h4><xsl:valu e-of select="attribu te::*"/></h4>
            </xsl:for-each>

            </xsl:template>

            </xsl:stylesheet>

            Comment

            • Dimitre Novatchev  [MVP XML]

              #7
              Re: Get root attribute values question 2

              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" <gimme_this_gim me_that@yahoo.c om> wrote in message
              news:3f12b4fb.0 404091416.35eb0 838@posting.goo gle.com...[color=blue]
              > 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]" <dnovatchev@yah oo.com> wrote in message[/color]
              news:<c56lvf$2n t0ro$1@ID-152440.news.uni-berlin.de>...[color=blue][color=green]
              > > Sorry, it's still not a well-formed xml document.
              > >
              > >
              > > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
              > > news:3f12b4fb.0 404090835.2a667 616@posting.goo gle.com...[color=darkred]
              > > > 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]" <dnovatchev@yah oo.com> wrote in message[/color]
              > > news:<c55rqk$2l 2cm8$1@ID-152440.news.uni-berlin.de>...[color=darkred]
              > > > > "GIMME" <gimme_this_gim me_that@yahoo.c om> wrote in message
              > > > > news:3f12b4fb.0 404081703.39989 dd0@posting.goo gle.com...
              > > > > > 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.[/color][/color][/color]


              Comment

              • Gadrin77

                #8
                Re: Get root attribute values question 2

                "Dimitre Novatchev [MVP XML]" <dnovatchev@yah oo.com> wrote in message news:<c589of$2o s176$1@ID-152440.news.uni-berlin.de>...[color=blue]
                > Use:
                >
                > preceding::a[1]/@some_attr
                >
                >
                > Cheers,
                >
                > Dimitre Novatchev [XML MVP],[/color]


                One line, sweet!

                Comment

                • gimme_this_gimme_that@yahoo.com

                  #9
                  Re: Get root attribute values question 2

                  asdfasd

                  Comment

                  Working...