XPath.. Getting sibling of ancestor

W

werD

Hello,

Im wondering about using xml to store relational data. It works well
with .net but im having some trouble with the xsl/xpath.

Lets say that I have an xml like

<data>
<files>
<file categoryid="1" name-"a file"/>
</files>
<filecategories>
<category id="1" name="System Tools"/>
</filecategories>
</data>

how would i do a relational xpath query like a join?

ive tried something like this but its not working to well
<xsl:for-each select="/data/file">
<xsl:value-of select="//category[@id=@categoryid]/@name" />
</xsl:for-each>


ive been reading about using an axis like ancestor::filecategories but
im not seeing an axis which would get the sibling of an ancestor
 
P

Philippe Poulard

werD said:
Hello,

Im wondering about using xml to store relational data. It works well
with .net but im having some trouble with the xsl/xpath.

Lets say that I have an xml like

<data>
<files>
<file categoryid="1" name-"a file"/>
</files>
<filecategories>
<category id="1" name="System Tools"/>
</filecategories>
</data>

how would i do a relational xpath query like a join?

ive tried something like this but its not working to well
<xsl:for-each select="/data/file">
<xsl:value-of select="//category[@id=@categoryid]/@name" />
</xsl:for-each>


ive been reading about using an axis like ancestor::filecategories but
im not seeing an axis which would get the sibling of an ancestor

hi,

try this :
<xsl:for-each select="/data/files/file">
<xsl:value-of select="//category[@id=current()/@categoryid]/@name" />
</xsl:for-each>

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
P

Peter Flynn

werD said:
Hello,

Im wondering about using xml to store relational data. It works well
with .net but im having some trouble with the xsl/xpath.

Lets say that I have an xml like

<data>
<files>
<file categoryid="1" name-"a file"/>
</files>
<filecategories>
<category id="1" name="System Tools"/>
</filecategories>
</data>

how would i do a relational xpath query like a join?

ive tried something like this but its not working to well
<xsl:for-each select="/data/file">
<xsl:value-of select="//category[@id=@categoryid]/@name" />
</xsl:for-each>


ive been reading about using an axis like ancestor::filecategories but
im not seeing an axis which would get the sibling of an ancestor

ancestor::filecategories/preceding-sibling::filecategories
(or following-sibling).

///Peter
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top