Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] xslt 1, node sets in variables

From: Joelle Tegwen <tegwe002@---.--->
To: xsl-list@-----.------------.---
Date: 8/3/2009 1:24:00 PM
Wow, thank you for explaining this to me in such detail. That was very 
helpful. I did get this to work. I found I didn't need the xsl:copy-of 
statement.

I never thought about doing a select statement like that; it hadn't 
occurred to me to try it like that. I can adjust the xpath statement to 
ensure I don't have logic errors like you described. I do like that 
better than the choose statement (which I really don't care to use). So 
I think in the end, I'll use that. But I can see that there might come a 
time when I need to use the rtf version.

Thank you much for your time, patience and encouragement.

Joelle

Wendell Piez wrote:
> Joelle,
>
> At 05:13 PM 7/31/2009, you wrote:
>> When I do what you suggested, it doesn't generate any errors, but I 
>> still don't get the result as a node-set. The copy-of statement dumps 
>> the xml of the tree to the output. Also, 
>> count(exsl:node-set($projects)) returns 1 (It should return 26 when 
>> there is no filter).
>
> Sorry, I forgot about this crucial detail.
>
> The data object being converted to the node set is a result tree 
> fragment. As such, it has a root. So when you count it, or rather the 
> node set resulting from converting it, (the count() function counts a 
> set of nodes), you get 1. It's a little tree.
>
> You are probably looking for count(node-set($projects)/*).
>
> You could also clarify things by using an extra variable, so:
>
> <xsl:variable name="projects-rtf">
>   <xsl:choose>
>     <xsl:when test="$active_filter = 'active'">
>       <xsl:copy-of select="project[@active!=0]"/>
>     </xsl:when>
>     <xsl:when test="$active_filter = 'archived'">
>       <xsl:copy-of select="project[@active=0]"/>
>     </xsl:when>
>     <xsl:when test="$active_filter = 'new'">
>       <xsl:copy-of select="project[@new=1]"/>
>     </xsl:when>
>     <xsl:otherwise>
>       <xsl:copy-of select="project"/>
>     </xsl:otherwise>
>   </xsl:choose>
> </xsl:variable>
>
> <xsl:variable name="projects" select="exsl:node-set($projects-rtf)/*"/>
>
> <xsl:copy-of select="$projects"/>
>
> <xsl:choose>
>   <xsl:when test="count($projects)>10">
>   etc.
>
> In this case, the variable $projects-rtf contains a result tree 
> fragment, and $projects contains copies (as nodes) of the actual 
> 'project' elements.
>
> Now, all this having been said, I'm going to take another step back to 
> see whether you even need an RTF to begin with. Why not just bind the 
> project elements themselves to your variable, instead of making copies 
> of them?
>
> Assuming things are not more complicated than you've shown, you might 
> be able to do this as:
>
> <xsl:variable name="projects"
>   select="project[$active_filter = 'active'][@active!=0] |
>           project[$active_filter = 'archived'][@active=0] |
>           project[$active_filter = 'new'][@new=1] |
>           project[not($active_filter = 'active' or
>                       $active_filter = 'archived' or
>                       $active_filter = 'new')]"/>
>
> Then you don't even need to use the node-set() function, since the 
> variable is already a node set (this time the actual nodes from the 
> source tree, not copies).
>
> This works by using XPath predicates to emulate your conditional 
> statements. And while it may be more cumbersome to read (if you don't 
> prefer your logic in XPath anyway: some do), it simplifies things 
> considerably both in your code and in the processing it specifies.
>
> But note I say "might" work since these conditionals are not actually 
> mutually exclusive. For example, if you have a 
> project[@new=1][@active=0], you will get it both for your 'new' filter 
> and your 'archived' filter. You can deal with this either by 
> controlling your input data to preclude such anomalous cases, or by 
> extending your filtering logic further.
>
> Keep asking about mysterious points, as this represents a big advance.
>
> Cheers,
> Wendell
>
>
> ======================================================================
> Wendell Piez                            mailto:wapiez@m...
> Mulberry Technologies, Inc.                http://www.mulberrytech.com
> 17 West Jefferson Street                    Direct Phone: 301/315-9635
> Suite 207                                          Phone: 301/315-9631
> Rockville, MD  20850                                 Fax: 301/315-8285
> ----------------------------------------------------------------------
>   Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================
>
>
> --~------------------------------------------------------------------
> 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@l...>
> --~--
>
>

--~------------------------------------------------------------------
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent