[xsl] multiple attributes

Subject: [xsl] multiple attributes
From: DPawson@xxxxxxxxxxx
Date: Fri, 13 Dec 2002 13:03:17 -0000
problem.

<xsl:param name="wanted" select="''"/>

<element att="a b c d">
wanted, contains both a and b

</element>

<element>

wanted, has no att attribute

</element>

<element att="x">
not wanted, block it.
</element>

I want to run an identity transform, but only 
select those elements which either have no @att,
or have an att value which is one of those passed into the stylesheet
as a command line param, e.g.

saxon file.xml ss.xsl "wanted= a b"

should only copy through those elements having an att value 
which contains one or both of a, b.

Hope that's clear.

I can't recall seeing a mxn contains string thingy.
I'm getting stuck with a recursion solution.
Any help appreciated.

TIA DaveP.



 <xsl:template match="*[@targets]">
    <xsl:variable name="inTarget">
    <xsl:call-template name="tgt">
      <xsl:with-param name="wanted" select="$targets"/>
      <xsl:with-param name="this-elements-targets" select="@targets"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$inTarget">
       <!-- Copy through, wanted -->
       <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates/>
       </xsl:copy>
    </xsl:when>


    <xsl:otherwise/>  <!-- block, not wanted -->
  </xsl:choose>
  </xsl:template>



 <xsl:template name="tgt">
    <xsl:param name="wanted" select="''"/>
    <xsl:param name="this-elements-targets" select="''"/>
    <xsl:if test="$debug">
      <xsl:message>
tgt: wanted   <xsl:value-of select="$wanted"/>
this els:   <xsl:value-of select="$this-elements-targets"/>
      </xsl:message>
    </xsl:if>
<xsl:variable name="onetarget"
select="substring-before($this-elements-targets,'+')"/>
      <xsl:if test="contains($wanted, $onetarget)">
        <xsl:value-of select="true"/>
      </xsl:if>

    <xsl:choose>
      <xsl:when test="string-length($this-elements-targets)= 0">
        <xsl:value-of select="false()"/>
      </xsl:when>
      

      <xsl:otherwise>
        <xsl:call-template name="tgt">
          <xsl:with-param name="this-elements-targets"
select="substring-after($this-elements-targets,'+')"/> <!-- presently uses +
character as seperator. perhaps change to space character -->
          <xsl:with-param name="wanted" select="$wanted"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>


  </xsl:template>


Regards DaveP.

**** snip here *****

- 

NOTICE: The information contained in this email and any attachments is 
confidential and may be legally privileged. If you are not the 
intended recipient you are hereby notified that you must not use, 
disclose, distribute, copy, print or rely on this email's content. If 
you are not the intended recipient, please notify the sender 
immediately and then delete the email and any attachments from your 
system.

RNIB has made strenuous efforts to ensure that emails and any 
attachments generated by its staff are free from viruses. However, it 
cannot accept any responsibility for any viruses which are 
transmitted. We therefore recommend you scan all attachments.

Please note that the statements and views expressed in this email 
and any attachments are those of the author and do not necessarily 
represent those of RNIB.

RNIB Registered Charity Number: 226227

Website: http://www.rnib.org.uk 

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


Current Thread