Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Get root attribute values question 2

Reply
Thread Tools

Get root attribute values question 2

 
 
GIMME
Guest
Posts: n/a
 
      04-09-2004
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.
 
Reply With Quote
 
 
 
 
Dimitre Novatchev [MVP XML]
Guest
Posts: n/a
 
      04-09-2004

"GIMME" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.



 
Reply With Quote
 
 
 
 
GIMME
Guest
Posts: n/a
 
      04-09-2004
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]" <(E-Mail Removed)> wrote in message news:<c55rqk$2l2cm8$(E-Mail Removed)-berlin.de>...
> "GIMME" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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.

 
Reply With Quote
 
Dimitre Novatchev [MVP XML]
Guest
Posts: n/a
 
      04-09-2004
Sorry, it's still not a well-formed xml document.


"GIMME" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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]" <(E-Mail Removed)> wrote in message

news:<c55rqk$2l2cm8$(E-Mail Removed)-berlin.de>...
> > "GIMME" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) om...
> > > 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.



 
Reply With Quote
 
GIMME
Guest
Posts: n/a
 
      04-09-2004
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]" <(E-Mail Removed)> wrote in message news:<c56lvf$2nt0ro$(E-Mail Removed)-berlin.de>...
> Sorry, it's still not a well-formed xml document.
>
>
> "GIMME" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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]" <(E-Mail Removed)> wrote in message

> news:<c55rqk$2l2cm8$(E-Mail Removed)-berlin.de>...
> > > "GIMME" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed) om...
> > > > 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.

 
Reply With Quote
 
Gadrin77
Guest
Posts: n/a
 
      04-10-2004
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 xmlnssl="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>
 
Reply With Quote
 
Dimitre Novatchev [MVP XML]
Guest
Posts: n/a
 
      04-10-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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]" <(E-Mail Removed)> wrote in message

news:<c56lvf$2nt0ro$(E-Mail Removed)-berlin.de>...
> > Sorry, it's still not a well-formed xml document.
> >
> >
> > "GIMME" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) om...
> > > 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]" <(E-Mail Removed)> wrote in message

> > news:<c55rqk$2l2cm8$(E-Mail Removed)-berlin.de>...
> > > > "GIMME" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed) om...
> > > > > 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.



 
Reply With Quote
 
Gadrin77
Guest
Posts: n/a
 
      04-10-2004
"Dimitre Novatchev [MVP XML]" <(E-Mail Removed)> wrote in message news:<c589of$2os176$(E-Mail Removed)-berlin.de>...
> Use:
>
> preceding::a[1]/@some_attr
>
>
> Cheers,
>
> Dimitre Novatchev [XML MVP],



One line, sweet!
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      01-10-2005
asdfasd

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"How To Get Attribute Value Of Root Element"? pbd22 Javascript 1 07-03-2007 02:27 PM
JNDI: Delete only one attribute when there are several different values for the same attribute bsporb@gmail.com Java 3 05-02-2007 05:41 AM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
How can I get attribute values to not get converted from &apos; to ' or &amp; to & or &lt; to > ? Sammy XML 12 05-06-2005 10:14 PM
Get root attribute values GIMME XML 3 04-12-2004 02:38 AM



Advertisments