Get root attribute values question 2

G

GIMME

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.
 
D

Dimitre Novatchev [MVP XML]

GIMME said:
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.
 
G

GIMME

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?
 
D

Dimitre Novatchev [MVP XML]

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


GIMME said:
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]" <[email protected]> wrote in message
Not in your case -- you must first have a well-formed xml document.
 
G

GIMME

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 said:
Sorry, it's still not a well-formed xml document.


GIMME said:
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]" <[email protected]> wrote in message
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.
 
G

Gadrin77

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>
 
D

Dimitre Novatchev [MVP XML]

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 said:
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]" <[email protected]> wrote in message
Sorry, it's still not a well-formed xml document.


GIMME said:
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]" <[email protected]> wrote in message
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top