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

Re: how to store node in variable?

Subject: Re: how to store node in variable?
From: John <john-xsl-list@xxxxxxxx>
Date: Thu, 21 Oct 2004 13:59:56 -0700
xsl variable condition
Thanks. Unfortunately that didn't really help me, but probably because I didn't describe my problem well. But, I do seem to have found an alternative. Not sure if this will make sense out of context:

 <xsl:choose>
   <xsl:when test="some condition">
     <xsl:for-each select="...">
       <xsl:call-template name="whatever" />
     </xsl:for-each>
   </xsl:when>
   <xsl:otherwise>
     <xsl:call-template name="whatever" />
   </xsl:otherwise>
 </xsl:choose>

I don't know why I didn't think of this in the first place.

G. Ken Holman wrote:

At 2004-10-21 12:39 -0700, John wrote:

How do I store a reference to a node in a variable


Only in the select= attribute.

or what am I doing wrong? Here is what I have (maybe oversimplified) :

<xsl:variable name="me">
  <xsl:choose>
    <xsl:when test="<some condition>">
      <xsl:copy-of select=".." />
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="." />
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable> <xsl:call-template name="<some template>">
  <xsl:with-param name="myid" select="$me/@id" />
</xsl:call-template>

The with-param is always throwing an error, expression should result in a node-set.


Right ... because it is a result tree fragment, not a node set.

If I add msxsl:node-set around my selects in the variable definition I get cannot convert result tree fragment to node-set.


Not sure why, but you'd get a copy of the node, not the node itself, so you would lose the context, so that wouldn't help (and it wouldn't be pure XSLT).

Alternatively, is there any way to explicitly set the context node without using for-each?


I would use:

    <xsl:variable name="condition" select="<some condition>"/>
    <xsl:variable name="me" select="../self::*[$condition] |
                                    self::*[not($condition)]"/>

Only one of the union would be in the result because the condition is true exactly once.

I hope this helps.

........................ Ken

--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.