Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Mon, 4 Feb 2008 08:21:35 -0800 (PST),    group: microsoft.public.xsl        back       


comments inside XSL   
Hi

I need to write an XSL that makes a transformation to an input xml
such as:
<tag1>
<email> test@hotmail.com </email>
</tag1>

 Such that I have an output:

<!--
<properties>
<email-property key="email" value="test@hotmail.com" />
</properties>
-->

I tried the following xsl:

<xsl:comment>
	<xsl:element name="properties">
		<xsl:element name=" email-property ">
			<xsl:attribute name="key">email</xsl:attribute>
				<xsl:attribute name="value">  <xsl:value-of select="//tag1/email"/
> </xsl:attribute>
		</xsl:element>
	</xsl:element>
</xsl:comment>

That gives the comment elements (<!--  -->) without the body. If I
remove the <xsl:comment>
I get the body without the comment elements in the output!

Thanks in advance
Mahmoud
date: Mon, 4 Feb 2008 08:21:35 -0800 (PST)   author:   unknown

Re: comments inside XSL   
khalil_mi@hotmail.com wrote:
> Hi
> 
> I need to write an XSL that makes a transformation to an input xml
> such as:
> <tag1>
> <email> test@hotmail.com </email>
> </tag1>
> 
>  Such that I have an output:
> 
> <!--
> <properties>
> <email-property key="email" value="test@hotmail.com" />
> </properties>
> -->
> 
> I tried the following xsl:
> 
> <xsl:comment>
> 	<xsl:element name="properties">
> 		<xsl:element name=" email-property ">
> 			<xsl:attribute name="key">email</xsl:attribute>
> 				<xsl:attribute name="value">  <xsl:value-of select="//tag1/email"/
>> </xsl:attribute>
> 		</xsl:element>
> 	</xsl:element>
> </xsl:comment>

See <URL:http://www.w3.org/TR/xslt#section-Creating-Comments>, the 
contents of xsl:comment should be text (nodes), not element nodes.
So you need to escape the markup


<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:template match="tag1">
     <xsl:copy>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="email">
     <xsl:comment>
       <xsl:text><properties>
<email-properties> key="email" value="</xsl:text>
       <xsl:value-of select="normalize-space(.)"/>
       <xsl:text>" />
</properties></xsl:text>
     </xsl:comment>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Mon, 04 Feb 2008 17:31:56 +0100   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us