This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: building of a variable which contains nodes


Stephane.Le-Deaut@alcatel.fr 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]