I think you're failing to retrieve the <fristName> you expect because
<xsl:for-each> has changed the current context to be your result-tree
fragemtn - rather than a node in the document.
One normal solution to this is to define a variable containing a node
from your input document before you enter the <xsl:for-each> loop.
e.g.
<xsl variable name='docroot' select='/wi:root'/>
and then use this variable to retrieve your desired <firstName>.
<td><xsl:value-of select="$docroot/changeLog/log[(_at_)id
= $cID]/@firstName" /></td>
I haven't tried this using a for-each loop on a node-set but it should work.
I'm never sure of the differences in the implementation of node-set in
different processors.
I have some style sheets using node-set that work fine under some XSLT
processors - but just throw errors under others.
HTH
Mike
Keyur K wrote:
Hello List,
I have a problem, I am not able to access any nodes/values from a Loop.
I have a sorted result tree fragment in a variable, I am using msxsl
node-set to loop through it.
Now when I need to access the other nodes of the document I am not
able to do so.
Pl. see below for the partial xsl and xml code. I have put two
comments in the xsl file one where I need the external node values but
not able to retrieve and second where I am able to retreive but do not
need
How can I access the outer/external nodes inside the loop, I also
tried using key() but it also didn't work inside the loop. It was
working fine outside the loop.
P.S. This xsl code is a part of a bigger xsl file.
Any advice will be very helpful. Thanks in advance.
- Keyur
<!------------XSL Partial Code ------------>
<xsl:template match="//changes" mode="changeLog">
<!--firstName IS AVAILABLE HERE-->
<xsl:variable name="sortedList">
<xsl:for-each select="./old">
<xsl:sort select="@changeID" data-type="number"
order="ascending"></xsl:sort>
<xsl:copy-of select="."></xsl:copy-of>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($sortedList)/old">
<xsl:variable name="cID"><xsl:value-of
select="@changeID"></xsl:value-of></xsl:variable>
<tr>
<!--firstName IS REQUIRED HERE BUT COULD NOT
RETRIEVE-->
<td><xsl:value-of
select="/wi:root/changeLog/log[(_at_)id = $cID]/@firstName" /></td>
<td><xsl:value-of select="./text()" /></td>
</tr>
</xsl:for-each>
</xsl:template>
<!------------XML Sample Code ------------>
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="abc.xsl"?>
<wi:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wi="abcxyz">
<content>
<personalData>
<lastName>Douglas</lastName>
<firstName>Michael</firstName>
<hobbies>
cricket, music, dancing, singing
<changes>
<old changeID="2">Hobbies</old>
<old changeID="4">cricket, music, dancing</old>
<old changeID="3">cricket, music</old>
</changes>
</hobbies>
</personalData>
</content>
<changeLog>
<log id="1" userID="8" firstName="Teri" date="8/13/2004" />
<log id="2" userID="7" firstName="Matt" date="8/13/2004" />
<log id="3" userID="15" firstName="Stephen" date="8/13/2004" />
<log id="4" userID="26" firstName="Bob" date="8/13/2004" />
</changeLog>
</wi:root>
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--
--
Datalucid Limited
8 Eileen Road
South Norwood
London SE25 5EJ
United Kingdom
/
tel :0208-239-6810
mob: 0794-725-9760
email: mike(_dot_)trotman(_at_)datalucid(_dot_)com
UK Co. Reg: 4383635
VAT Reg.: 798 7531 60
/