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: Thu, 20 Mar 2008 20:23:30 +0100,    group: microsoft.public.xsl        back       


Search and replace strings   
I need to add 'px' to font-size values like those in this xml: 

<style> 
   .class1{
      font-family:Arial;
      font-size:25;
   }
   .class2{ 
      font-family:Arial Bold;
      font-size:20;
   }
</style>

So it should be for example font-size:25px;

Can someone please give some tips on how to do this with xsl? I have to use MSXML4.
date: Thu, 20 Mar 2008 20:23:30 +0100   author:   Ralph Wiggum

Re: Search and replace strings   
Figured it out by myself:

<xsl:template match="style">	
	<xsl:copy>	
		<xsl:apply-templates select="@*"/>		
		<xsl:call-template name="stylehead">
			<xsl:with-param name="s" select="."/>          
		</xsl:call-template>		
	</xsl:copy>
</xsl:template>

<xsl:template name="stylehead">
	<xsl:param name="s"/>	
	<xsl:choose>		
		<xsl:when test="contains($s, 'font-size:')">
			<!--Keep text up to-->
			<xsl:value-of select="substring-before($s,'font-size:')"/>
			<xsl:call-template name="styletail">
				<xsl:with-param name="s" select="substring-after($s, 'font-size:')"/>
			</xsl:call-template>			
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$s"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="styletail">
	<xsl:param name="s"/>	
	<xsl:if test="string-length($s)>0">
		<!-- keep value, add unit-->
		<xsl:value-of select="concat('font-size:', substring-before($s,';'), 'px;')"/>
		<xsl:call-template name="stylehead">
			<xsl:with-param name="s" select="substring-after($s, ';')"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

Ralph Wiggum wrote:
> I need to add 'px' to font-size values like those in this xml:
> <style>   .class1{
>      font-family:Arial;
>      font-size:25;
>   }
>   .class2{      font-family:Arial Bold;
>      font-size:20;
>   }
> </style>
> 
> So it should be for example font-size:25px;
> 
> Can someone please give some tips on how to do this with xsl? I have to 
> use MSXML4.
date: Thu, 20 Mar 2008 23:21:00 +0100   author:   Ralph Wiggum

Google
 
Web ureader.com


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