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

Re: Re: Thought i knew this but i guess not

Subject: Re: Re: Thought i knew this but i guess not
From: russurquhart1@xxxxxxxxxxx
Date: Tue, 22 Feb 2011 14:38:14 -0600 (CST)
Re: Re:  Thought i knew this but i guess not
Hi Everyone,

I just can't get this today. (Maybe i need more sleep.)

I have the following, trying to follow Wendell'sadvice:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*[@filter]">
    <xsl:choose>
      <xsl:when test="(not(contains(@filter, 'filter10'))) and (not(contains(@filter, 'filter1')))">
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="." />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
 
</xsl:stylesheet>

I want this to work kind of like a conditional text thing. When i run this i get NO elements with a filtered attribute.

Little more help for the slow kid? :)

thanks,


Russ
Feb 22, 2011 07:35:48 PM, xsl-list@xxxxxxxxxxxxxxxxxxxxxx wrote:

Russ,

On 2/22/2011 2:19 PM, russurquhart1@xxxxxxxxxxx wrote:
> I am trying to extract only elements having a filter attribute value of 'filter10', 'filter1' or has no filter attributes at all. I would have thought this would do it:
>
> But other filter values are making it into the result file.

Naturally. Using the templates you've given, there are two things you 
could get in your result:

If the document element (/*) has a @filter containing 'filter10' or 
'filter1', or no @filter at all, you'll get the entire document.

Otherwise you'll get nothing.

This is because xsl:copy-of simply copies a branch of the tree to the 
result. Since either one or the other of your templates will match the 
element at the top of the document, either it will be copied with all 
its attributes and descendants, or it won't.

 From your question it appears you expect the templates to match 
recursively down through a full traversal of the tree. But the copy-of 
instruction doesn't do that. Instead, you want the identity template, 
which uses xsl:copy (not copy-of) and xsl:apply-templates, to effect a 
traversal in the normal way.

So basically what you want is a copy of the identity template, plus 
another template that overrides it for elements matching elements you 
don't want to copy, which does something special for them. (But we can't 
write that template until you say whether the contents of these elements 
might still be copied, or you expect the tree simply to be truncated at 
those points.)

If you have trouble working it out based on this hint, I'm sure another 
helpful list member can be more explicit.

Cheers,
Wendell

> 
>    
>      
>
>        
>      
>    
>    
>      
>    
> 
>
>
> Can someone provide some help on this!
>
> Thanks so much!

-- 
======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
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
======================================================================

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.