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

Re: building of a variable which contains nodes

Subject: Re: building of a variable which contains nodes
From: "Mitch C. Amiano" <Mitch.Amiano@xxxxxxxxxxx>
Date: Mon, 03 Dec 2001 10:28:31 -0500
select from where contains
Stephane.Le-Deaut@xxxxxxxxxx wrote:
> 
> Hello,
> 
> I would like to create a variable which contains nodes. The node comes from the newReferenceAuthentifiedPackageDescriptorFile file or the currentAuthentifiedPackageDescriptorFile file. If i use <xsl:if> element my code is like this :
> 
> <xsl:if test="$buildingType='EXCEPTION_PROCEDURE' ">
>     <xsl:variable name="ListOfServiceDescriptor"
>           select="$currentAuthentifiedPackageDescriptorFile
>          //Subset[normalize-space(@serviceName)!='' and
>          .//SingleElement/@isVersionned='YES']"/>
> 
>     <xsl:call-template name="makeRootDescriptor">
>        <xsl:with-param name="listOfServiceDescriptor"
>                        select="$ListOfServiceDescriptor"/>
>     </xsl:call-template>
> </xsl:if>

Used in this way, the variable construct is really just a 
shorthand for the XPath.  

> <xsl:if test="$buildingType='STANDARD' ">
>     <xsl:variable name="ListOfServiceDescriptor"
>           select="$newReferenceAuthentifiedPackageDescriptorFile
>                                //Subset[contains($servicesDescriptor,@serviceName)]"/>
> 
>     <xsl:call-template name="makeRootDescriptor">
>        <xsl:with-param name="listOfServiceDescriptor"
>                        select="$ListOfServiceDescriptor"/>
>     </xsl:call-template>
> </xsl:if>
> 
> This program works fine, but I don't want  to duplicate the call of the makeRootDescriptor template.
> I want to call this template once. So I'm trying to solve my problem by using <xsl:choose> element like this
> 
> <xsl:variable name="ListOfServiceDescriptor">
>       <xsl:choose>
>        <xsl:when test="$buildingType='EXCEPTION_PROCEDURE' ">
> 
>          <xsl:value-of select="$newReferenceAuthentifiedPackageDescriptorFile
>                                //Subset[contains($servicesDescriptor,@serviceName)]"/>
>        </xsl:when>
>        <xsl:otherwise>
>          <xsl:value-of select="$currentAuthentifiedPackageDescriptorFile//Subset[normalize-space(@serviceName)!='' and
>                                                                                                                                       .//SingleElement/@isVersionned='YES']"/>
>        </xsl:otherwise>
>       </xsl:choose>
> </xsl:variable>
> 
>     <xsl:call-template name="makeRootDescriptor">
>        <xsl:with-param name="listOfServiceDescriptor"
>                        select="$ListOfServiceDescriptor"/>
>     </xsl:call-template>
> 
> But it doesn't work because <xsl:value-of> element returns a string value, so I got this message :
> XPATH: Can not convert #RTREEFRAG to a NodeList!
 
RTREEFRAG means "Result TREE FRAGment". Your code converts the source
nodes to a result tree fragment,
and your XSLT processor doesn't (apparently) support any extensions to
navigate the result as 
a normal node set. Some processors can do this.

As an alternative, I often use fixed predicates ( somefixedvalue = 0 )
with "and" or "or" to
coerce a query language into a specific behavior. In your case, the
"buildingType" is known
in advance of the XPath, and can be used as an additional predicate. You
may want to use
something like this:

<xsl:variable name="StandardProc"
select="$newReferenceAuthentifiedPackageDescriptorFile//Subset[
   contains($servicesDescriptor,@serviceName)
   ][ $buildingType='STANDARD' ]">
<xsl:variable name="ExceptionProc"
select="$newReferenceAuthentifiedPackageDescriptorFile//Subset[
   contains($servicesDescriptor,@serviceName)
   ][ $buildingType='EXCEPTION_PROCEDURE ]">
<xsl:variable name="ListOfServiceDescriptor"
select="$StandardProc|$ExceptionProc">

I don't know if my syntax is perfect. Using filters one after another in
this way 
is effectively "and" logic.

> Does there exist another approach ?

I just saw David Carlisle's solution which looks like it works out the
same but
eliminates the variables.

> Is the <xsl:if> element is the only solution ?
> 
> Thanks for your help.
> Stéphane
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

--
Mitch.Amiano (@alcatel.com)
SW Development Engineer in C++/Java/Perl/TCL/SQL/XML/XSLT/XPath
Advance Design Process Group, Raleigh Engineering Services     Alcatel
USA

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.