Re: [xsl] Trouble using document()

Subject: Re: [xsl] Trouble using document()
From: omprakash.v@xxxxxxxxxxxxx
Date: Fri, 10 Jun 2005 15:12:58 +0530
Hi,

You have 2 nested for-each loops one iterating over nodes in the document
($nodeFileName) and another with nodes in the "pd:" namespace.

      <xsl:for-each select="document($nodeFileName)/nodes/n">
           <xsl:variable name="found">
             <xsl:for-each select="pd:stats">

When the first for-each gets executed the context node shifts to the
document($nodeFileName) file and the second for-each looks for the pd:stats
in the same document where the context node is. If you'd like to look for
pd:stats in the current document, then you can do:

      <xsl:for-each select="document($nodeFileName)/nodes/n">
           <xsl:variable name="found">
             <xsl:for-each select="document
('')/pd:electrodeStatsList/pd:stats">


Hope this helps.

Cheers,
Omprakash.V




                                                                                                                      
                    "mwebster"                                                                                        
                    <mwebster@combim        To:     <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                 
                    atrix.com>              cc:     (bcc: omprakash.v/Polaris)                                        
                                            Subject:     [xsl] Trouble using document()                               
                    06/10/2005 01:40                                                                                  
                    PM                                                                                                
                    Please respond                                                                                    
                    to xsl-list                                                                                       
                                                                                                                      
                                                                                                                      






Sorry if I have included too much or too little of my XSL document.  This
section is attempting to replace a recursive solution that worked well in
Saxon but causes a stack overflow error in XALAN.

Basically, I want to use the known number of nodes in

document($nodeFileName)/nodes/n

to go through my smaller list of stats in my main XML document to produce a
known number of nodes in the final XML.  I believe I am getting some
confusion between the document() items and the items in my pd: XML because
sections like:

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


don't seem to be getting accessed at all.

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:

Can anyone suggest what I'm doing wrong?




<xsl:template match="pd:electrodeStatsList">
<xsl:element name="electrodeStatsList" namespace
="urn:probe-design-service">
    <xsl:element name="statsNamesList" namespace
="urn:probe-design-service">
           <xsl:for-each select="pd:stats[1]/pd:stat">
               <xsl:element name="statName"
namespace="urn:probe-design-service">
                     <xsl:value-of select="@name" />
               </xsl:element>
           </xsl:for-each>
    </xsl:element>
<!-- Handle full set of electrode data -->
      <xsl:if test="$useLoop = 'false'">
             <xsl:for-each select="pd:stats">
                 <xsl:element name="stats"
namespace="urn:probe-design-service">
                       <xsl:for-each select="pd:stat">
                           <xsl:element name="st"
namespace="urn:probe-design-service">
                                 <xsl:value-of select="." />
                           </xsl:element>
                       </xsl:for-each>
                 </xsl:element>
             </xsl:for-each>
    </xsl:if>
<!-- Handle sparse electrode data -->
    <xsl:if test="$useLoop = 'true'">
      <xsl:for-each select="document($nodeFileName)/nodes/n">
           <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>
           <xsl:choose>
             <xsl:when test="$found = 'true'">
               <xsl:for-each select="pd:stats">
                 <xsl:if test="@index = position()-1">
                     <xsl:element name="stats"
namespace="urn:probe-design-service">
                         <xsl:for-each select="pd:stat">
                               <xsl:element name="st"
namespace="urn:probe-design-service">
                                   <xsl:value-of select="." />
                               </xsl:element>
                         </xsl:for-each>
                     </xsl:element>
                 </xsl:if>
               </xsl:for-each>
             </xsl:when>
             <xsl:otherwise>
               <xsl:element name="stats" namespace
="urn:probe-design-service">
                 <xsl:for-each select="pd:stats[1]/pd:stat">
                     <xsl:element name="st" namespace
="urn:probe-design-service"
/>
                 </xsl:for-each>
               </xsl:element>
             </xsl:otherwise>
           </xsl:choose>
      </xsl:for-each>
    </xsl:if>
</xsl:element>
</xsl:template>




Michael Webster
CombiMatrix Corporation
Software Department
(425) 493-2266






This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread