[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Newbie Problem

Subject: Re: Newbie Problem
From: Mike Trotman <mike.trotman@xxxxxxxxxxxxx>
Date: Sat, 14 Aug 2004 12:23:56 +0100
msxsl current date
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[@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[@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>


--
Datalucid Limited
8 Eileen Road
South Norwood
London SE25 5EJ
United Kingdom

/
tel :0208-239-6810
mob: 0794-725-9760
email: mike.trotman@xxxxxxxxxxxxx

UK Co. Reg:   4383635
VAT Reg.:   798 7531 60

/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.