xsl-list
[Top] [All Lists]

Re: Trouble using document()

2005-06-10 02:30:28
  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[(_at_)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
________________________________________________________________________

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>