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

Re: Checking Value or element in XSL

Subject: Re: [xsl]Checking Value or element in XSL
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 18 Nov 2004 05:03:15 -0800 (PST)
xsl attribute name value
Hi Arul,
  Here is a slightly modified XSL -

<xsl:for-each select="child::*">
  <cs>
    <xsl:attribute name="attribute">
      <xsl:value-of select="name()"/>
    </xsl:attribute>
    <xsl:attribute name="value">
      <xsl:choose>
        <xsl:when test="normalize-space(text()) = ''">
	  <xsl:for-each select="child::*">
	    <xsl:value-of select="text()"/>
            <xsl:if test="position() != last()">
              <xsl:text> </xsl:text>
            </xsl:if>  
	  </xsl:for-each>
	</xsl:when>
        <xsl:otherwise>
	  <xsl:value-of select="text()"/>
	</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </cs>
</xsl:for-each>

Please notice the use of normalize-space() function
(which makes all the difference).

This node (1)
<Name>
  <FirstName>Arul</FirstName>
  <LastName>Raj</LastName>
</Name>

is different from (2)
<Name><FirstName>Arul</FirstName><LastName>Raj</LastName></Name>

in case (1), a text node after <Name> is not empty;
because it has white characters(newline & blank
spaces).

Regards,
Mukul

--- Arulraj <p_arulraj@xxxxxxxxx> wrote:

> Hello,
> 
> I have the following xml elements;
> <Person>
>   <Num>1</Num>
>    <Name>
>         <FirstName>Arul</VorName>
> 	<LastName>Raj</NachName>
>    </Name>
> </Person>
> 
> I need the following output 
> 
> <cs attribute="Num" value= "1"/>
> <cs attribute="Name" value ="Arul Raj"/>
> 
> I have used following XSLT.
> 
> <xsl:for-each select="child::*">
> <cs>
> <xsl:attribute name="attribute">
> 							  <xsl:value-of select="name()"/>
> 							</xsl:attribute>
> 							<xsl:attribute name="value">
> 							<xsl:choose>
> 							<xsl:when test="(text()='')">
> 							<xsl:for-each select="child::*">
> 							<xsl:value-of select="text()"/><xsl:text>
> </xsl:text>
> 							</xsl:for-each>
> 							</xsl:when>
> 							<xsl:otherwise>
> 							<xsl:value-of select="text()"/>
> 							</xsl:otherwise>
> 							</xsl:choose>
> 							</xsl:attribute>
> 							</cs>
> 
> </xsl:for-each>
> 
> I am getting following output:
> <cs attribute="Num" value="1"/>
> 							<cs attribute="Name" value="
 "/>
> 
> How to solve this ?
> 
> thanks
> regards,
> Arul



		
__________________________________ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 

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.