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

RE: How to check whether any of child node with partic

Subject: RE: How to check whether any of child node with particular tagname h as non-empty String value
From: Ivan Pedruzzi <ipedruzz@xxxxxxxxxxxx>
Date: Fri, 31 Jan 2003 16:31:19 -0500
xsl check empty string
Assuming your xml source is

<?xml version="1.0"?>
<root>
  <ATTACHMENT>
    <ATTACHMENT_NAME></ATTACHMENT_NAME>
    <ATTACHMENT_LINK>http://yahoo.com</ATTACHMENT_LINK>
    <ATTACHMENT_NAME>link</ATTACHMENT_NAME>
    <ATTACHMENT_LINK>http://msn.com</ATTACHMENT_LINK>
  </ATTACHMENT>
  <ATTACHMENT>
    <ATTACHMENT_NAME>link2</ATTACHMENT_NAME>
    <ATTACHMENT_LINK>http://msn.com</ATTACHMENT_LINK>
  </ATTACHMENT>
</root>

You could do

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html"/>
 <xsl:template match="/">
  <html><body>
  <P><B>ATTACHMENT:</B></P>
    <xsl:for-each select="root/ATTACHMENT">
     <xsl:for-each
select="child::ATTACHMENT_NAME[string(normalize-space(.))]">
      <xsl:variable name="href"
select="following-sibling::ATTACHMENT_LINK[1]"/>
      <a href="{$href}"><xsl:apply-templates/></a>
      <br/>
     </xsl:for-each>
    </xsl:for-each>
   </body></html>
 </xsl:template>
</xsl:stylesheet>

Ivan

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Wang, Dongzhi (ACF)
> Sent: Friday, January 31, 2003 4:06 PM
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: RE:  How to check whether any of child node 
> with particular tag name h as non-empty String value
> 
> 
> 
> Thanks for the suggesion.  But I forgot to mention I should 
> only output "<B>ATTACHMENT:</B>" EXACTLY one time, like:
> 
> ATTACHMENT: link1
> link2
> 
> With your suggestion, the output will be like:
> 
> ATTACHMENT: link1
> ATTACHMENT: link2
> 
> Could you please give me any other suggestion?
> 
> Thanks!
> Dongzhi
> 
> 
> -----Original Message-----
> From: Ivan Pedruzzi [mailto:ipedruzz@xxxxxxxxxxxx]
> Sent: Friday, January 31, 2003 3:44 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  How to check whether any of child node 
> with particular tag name h as non-empty String value
> 
> 
> 
> Try this
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:output method="html"/>
>  <xsl:template match="ATTACHMENT">
>   <html><body><P>
>      <B>ATTACHMENT:</B>
>      <xsl:for-each 
> select="child::ATTACHMENT_NAME[string(normalize-space(.))]">
>       <xsl:variable name="href" 
> select="following-sibling::ATTACHMENT_LINK[1]"/>
>       <br/>
>       <a href="{$href}">
>        <xsl:apply-templates/>
>       </a>
>      </xsl:for-each>
>     </P></body></html>
>    </xsl:template>
> </xsl:stylesheet>  	
> 
> 
> Ivan
> 
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> > Wang, Dongzhi (ACF)
> > Sent: Friday, January 31, 2003 3:14 PM
> > To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> > Subject:  How to check whether any of child node with 
> > particular tag name h as non-empty String value
> > 
> > 
> > Hi All,
> > 
> > I run into a problem where I'm not able to check  whether any
> > of child node with particular tag name has empty String value.  
> > 
> > Here's the XML:
> > 
> > 	<ATTACHMENT>
> > 		<ATTACHMENT_NAME></ATTACHMENT_NAME>
> > 		<ATTACHMENT_LINK> http://yahoo.com </ATTACHMENT_LINK>
> > 		<ATTACHMENT_NAME> link </ATTACHMENT_NAME>
> > 		<ATTACHMENT_LINK> http://msn.com </ATTACHMENT_LINK>
> > 	</ATTACHMENT>
> > 
> > The requirement is to do something ANY of the
> > <ATTACHMENT_NAME> elemement has non-empty String.  Here's the 
> > XSL I wrote:
> > 
> >   	<xsl:template match="ATTACHMENT">
> > 		<xsl:if
> > test="string(normalize-space(child::ATTACHMENT_NAME))">
> > 			<P>
> > 				<B>ATTACHMENT:</B>
> > 				<xsl:for-each select="ATTACHMENT_NAME">
> > 					<xsl:variable 
> > name="href" select="following-sibling::ATTACHMENT_LINK" />
> > 					<a href ="{$href}">
> > 						<xsl:apply-templates />
> > 					</a>
> > 					<br/>
> > 				</xsl:for-each>
> > 			</P>
> > 		</xsl:if>
> >   	</xsl:template>
> > 
> > But from the result I got, seems like the decision is only
> > based on the first <ATTACHMENT_NAME> element it found, and 
> > totally ignore the later ones. i.e. if the first 
> > <ATTACHMENT_NAME> has empty String value but the second one 
> > has String value "link" in it, it won't fall into the if block. 
> > 
> > Thanks in advance for any suggestions!
> > 
> > Dongzhi
> > 
> > 
> >  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> > 
> 
>  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.