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

RE: multiple attributes

Subject: RE: multiple attributes
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Fri, 13 Dec 2002 16:04:52 -0000
mailto multiple attachments
Hi Dave.
If the attribute are small strings use the template with mode="block"
Just do:
<xsl:apply-templates mode="block"/>

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
DPawson@xxxxxxxxxxx
Sent: sexta-feira, 13 de Dezembro de 2002 15:42
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  multiple attributes




> -----Original Message-----
> From: Américo Albuquerque [mailto:aalbuquerque@xxxxxxxxxxxxxxxx]
> Sent: 13 December 2002 15:04
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  multiple attributes
> 
> 
> Hi Dave.
> The following stylesheet has two modes, the default checks if the @att

> has any of the chars entered, the block mode checks if the @att has 
> any of the words entered.
> 
> Example:
> If wanted='ab' then the default mode copies all nodes that
> has the char
> 'a' or the char 'b', the 'block' mode only copy the nodes that has the
> word 'ab' on the @att attribute.
> If wanted='a b' (your example) then the default mode copies all nodes
> that has the char 'a' or the char 'b', the 'block' mode only copy the
> nodes that has the word 'a' or the word 'b' on the @att attribute.
> 
> Hope that this helps you.

Drat, my example was too simple.
  The actual attribute values are small strings, i.e. the translate()
function isn't applicable without some of Dimitre's magic :-)

E.g. it could be (is, in the real example)
<element att="xml bpr training">

Sorry, I was trying to keep it clear.
  I'll look at how you've worked it though.
regards DaveP



> 
> Stylesheet:
>  <xsl:param name="wanted" select="'a b'"/>
>  <xsl:variable name="attrs" select="translate($wanted,' ','')"/> <!-- 
> this is for the default mode -->  <xsl:variable name="attr2"> <!-- 
> this is for 'block' mode -->  <xsl:call-template name="break"/>
>  </xsl:variable>
>  
>  <xsl:template match="*">
>   <xsl:choose>
>    <xsl:when test="not(translate(@att,$attrs,'')=@att) or not(@att)">
>    <xsl:copy>
>    <xsl:copy-of select="@*"/>
>    <xsl:apply-templates/>
>    </xsl:copy>
>    </xsl:when>
>   </xsl:choose>
>  </xsl:template>
>  
>  <xsl:template match="*" mode="block">
>   <xsl:variable name="curr_node" select="."/>
>   <xsl:variable name="attr">
>   <xsl:for-each select="msxsl:node-set($attr2)/attr"><!--
> you'll need a
> node-set function here -->
>    <xsl:if test="contains(concat(' ',$curr_node/@att,' 
> '),concat(' ',.,'
> '))">
>    <xsl:text>1</xsl:text>
>    </xsl:if>
>   </xsl:for-each>
>   </xsl:variable>
> 
>   <xsl:if test="string($attr) or not(@att)">
>    <xsl:copy>
>    <xsl:copy-of select="@*"/>
>    <xsl:apply-templates/>
>    </xsl:copy>
>   </xsl:if>
>  </xsl:template>
>  
>  <xsl:template name="break">
>   <xsl:param name="s" select="$wanted"/>
>   <xsl:choose>
>    <xsl:when test="contains($s,' ')">
>    <attr><xsl:value-of select="substring-before($s,' ')"/></attr>
>    <xsl:call-template name="break">
>     <xsl:with-param name="s" select="substring-after($s,' ')"/>
>    </xsl:call-template>
>    </xsl:when>
>    <xsl:otherwise>
>    <attr><xsl:value-of select="$s"/></attr>
>    </xsl:otherwise>
>   </xsl:choose>
>  </xsl:template>
> 
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> DPawson@xxxxxxxxxxx
> Sent: sexta-feira, 13 de Dezembro de 2002 13:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  multiple attributes
> 
> 
> 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
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

- 

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


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


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.