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

Re: Trouble using document()

Subject: Re: Trouble using document()
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 10 Jun 2005 10:30:28 +0100
xs for each select document
  That is, I think when I reference pd:stats, the XLST is thinking I'm
  referring to something in document($nodeFileName) rather than something in
  my main XML file in the name space pd:

That's because it is refering to nodes in that document. XPaths always
refer to nodes in the current document unless they begin with a variable
holding (or function returning) a node from another ocument.

The usual suggestion is to go

<xsl:variable name="root" select="/"/>
<xsl:variable name="here" select="."/>
<xsl:for-each select="document().....">
...
   <xsl:value-of select="$here/a/b"/>
when you want to refer to an XPath starting from where you were before 
the xs:for-each

or
   <xsl:value-of select="$root/a/b"/>
to refer something relative to the top of that document.

However this is slightly strange

<xsl:variable name="found">
	  <xsl:for-each select="pd:stats">
	    <xsl:if test="@index = position()-1">
	      <xsl:value-of select="'true'"/>
	    </xsl:if>
	  </xsl:for-each>
	</xsl:variable>

t wil make a variable with a result tree fragment writh a root node an a
text node consisting of truetruetrue with one true for every pd:stats
that has an index attribute equal to teh number of its preceding
siblings.

I suspect that you just mean to test if there is such an elemnt
which you could do by
<xsl:variable name="found" select="pd:stats[@index = position()-1]">

this node set will be empty or not depending on whether there are any
such elements so then you can go

<xsl:if test="$found"...

rather than
<xsl:if test="$found='true'"...


(Actually if there is the possibility of tehre being two elements 
and you do mean to only be true if there is one then you could do
<xsl:if test="$found and not($found[2])"...
otherwise in you version you'd need to use starts-with() rather than =
as the string might be truetrue rather than just true.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.