Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using current() to get to document root 2

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I am trying to get back to the root of a document using the current() function, can anyone help ?

xml
Code:
<Root>
<node1>
<node2/>
</node1>
</Root>

DataIsland.xsl
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:edi="[URL unfurl="true"]http://">[/URL]

<edi:test type="node1" value="foobar"/>

</xsl:stylesheet>

template
Code:
<xsl:template match="node2">
<!-- this works -->
<xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type='node1']/@value"/>
<!-- but i want to do something like this -->
<xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type=name(current()Root/*)]/@value"/>
</xsl:template>

Thanks in advance
 
><xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type=name(current()Root/*)]/@value"/>
Can you put it in words so we understand the purpose and work from there on?
 
sure - it's just a little difficult to explain.

I am using a data island to store data which I want to look up while traversing a node set.

However, I want to use the root node of my data as part of the look up.

So while I know the details of the current node (node2) I want to know the name of the root node (Root).

I do not know how deep I would be in the tree, so navigating up the tree would not be an option.

Hope this helps
 
Off-hand, something like this?
><xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type=name(current()Root/*)]/@value"/>
[tt]<xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type=name(current()[red]/ancester-or-self::*[count(ancester::*)=0][/red])]/@value"/>[/tt]
 
Correction
ancestor not ancester!
[tt]<xsl:value-of select="document('DataIsland.xsl')/xsl:stylesheet/edi:test[@type=name(current()[red]/ancest[highlight]o[/highlight]r-or-self::*[count(ancest[highlight]o[/highlight]r::*)=0][/red])]/@value"/>[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top