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

Re: how to match the absence of a particular attribute

Subject: Re: how to match the absence of a particular attribute
From: meesala dinesh <meesala74@xxxxxxxxx>
Date: Mon, 30 May 2005 18:00:44 -0700 (PDT)
dinesh meesala
 For example:
> 
> <A>
>    <B a="a">hello2</B>
>    <B a="a" b="b">hello3</B>
>    <B>hello1</B>   
>    <B b="b">hello4</B>
> </A>

1)abscence of "a" attribute 
----------------------------       
      In this case you need to choose the indirect
approach

<xsl:template match="A">
  <xsl:for-each select="B">
   <xsl:choose>
    <xsl:when test="@a != ''"/>
    <xsl:otherwise>			
	<xsl:copy-of select="."/>
    </xsl:if>
   </xsl:choose>				
  </xsl:for-each>
</xsl:template>

result: 
<B>hello1</B>
<B b="b">hello4</B>

2)"a" attribute is present but value is empty
---------------------------------------------
example:
<A>
>    <B a="a">hello2</B>
>    <B a="a" b="b">hello3</B>
>    <B a="">hello1</B>   
>    <B b="b">hello4</B>
> </A>
    In the second case you can go for the direct
approach.

<xsl:template match="A">
   <xsl:for-each select="B">		
     <xsl:if test="@a ='' ">
	<xsl:copy-of select="."/>
     </xsl:if>
   </xsl:for-each>
</xsl:template>

result:
<B a="">hello1</B>


cheers,
Dinesh M.S

-------------------------------------------------------
--- talosso@xxxxxxxxx wrote:

> Hi,
> 
> my problem is different, I need to match a node that
> have NOT a
> particular attribute.
> Imagine a sequance of node of the same type which
> can have attributes or not.
> I need to perform a first match and if an particular
> attribute is
> absent I will have to perform a second match,
> otherwise the first
> match is enough.
> 
> For example:
> 
> <A>
>    <B a="a">hello2</B>
>    <B a="a" b="b">hello3</B>
>    <B>hello1</B>   
>    <B b="b">hello4</B>
> </A>
> 
> I match the first two "B" nodes as is (the XSLT
> rewrite them without
> translating)
> for the third "B" node, since it lacks the "a"
> attribute, the XSLT
> will perform a second match looking for the next "B"
> node.
> 
> Is it possible to match the absence of an attribute
> with xsl?
> 
> On 5/30/05, omprakash.v@xxxxxxxxxxxxx
> <omprakash.v@xxxxxxxxxxxxx> wrote:
> > 
> > 
> > Hi,
> >   Try this:
> > 
> > <xsl:if test="@id">
> >   <!--   do something if attribute id exists -->
> > </xsl:if>
> > 
> > 
> > Cheers,
> > prakash
> > 
> > 
> > 
> > 
> >                    <talosso@gmai
> >                    l.com>               To:    
> XSL List <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >                                         cc:    
> (bcc: omprakash.v/Polaris)
> >                    05/30/2005           Subject:  
>    how to match the absence of a particular
> attribute
> >                    02:28 PM
> >                    Please
> >                    respond to
> >                    xsl-list
> > 
> > 
> > 
> > 
> > 
> > 
> > Hi guys,
> > 
> > how can I test the presence of a particular
> attribute of a node in an
> > "if" or "choose" tag?
> > I need to drive the behavior of the translation in
> two different ways,
> > if an attribute exists or not. I suppose the key
> point is the
> > capability to match the absence of an attribute,
> but I have found no
> > way to do this.
> > 
> > Thank you very much for any help.
> > 
> > Livio
> > 
> > 
> > 
> > 
> > 
> > 
> > This e-Mail may contain proprietary and
> confidential information and is sent for the
> intended recipient(s) only.
> > If by an addressing or transmission error this
> mail has been misdirected to you, you are requested
> to delete this mail immediately.
> > You are also hereby notified that any use, any
> form of reproduction, dissemination, copying,
> disclosure, modification,
> > distribution and/or publication of this e-mail
> message, contents or its attachment other than by
> its intended recipient/s is strictly prohibited.
> > 
> > Visit Us at http://www.polaris.co.in
> 
> 



		
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

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.