xsl-list
[Top] [All Lists]

Re: [xsl] Thought i knew this but i guess not

2011-02-22 15:44:06
Russ,

You are almost there.

First, you want xsl:apply-templates, not xsl:value-of. xsl:apply-templates will continue template matching through the tree. xsl:value-of will write the string value of the element, without processing children with templates.

Second, don't forget to do the usual xsl:copy thing for the elements you don't want to filter out.

Then, I suggest you might invert your logic for clarity.

Something like this?

<xsl:template match="*[@filter]">
  <xsl:choose>
<xsl:when test="(contains(@filter, 'filter10')) or contains(@filter, 'filter1'))">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise/>
  </xsl:choose>
</xsl:template>

This, of course, easily reduces to an xsl:if.

If that doesn't do it, maybe making a minimal test sample for demonstration would help.

Finally, I note that your test for your filter is brittle. @filter='filter11' will pass. (And 'filter10' will pass for two reasons.) The best fix to this depends on how you are using @filter.

Cheers,
Wendell

On 2/22/2011 3:38 PM, russurquhart1(_at_)verizon(_dot_)net wrote:
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(_at_)lists(_dot_)mulberrytech(_dot_)com 
wrote:
--
======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--