[xsl] code review

Subject: [xsl] code review
From: "Theresa Devine" <tdevine@xxxxxxxxxxxx>
Date: Fri, 20 Feb 2004 13:48:13 -0600
I was wondering if ya'll might review my xslt and see if there is a more
efficient way of doing this transformation. The part I have questions
about is the search and replace.... 

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>   

<xsl:param name="sycampusid"></xsl:param>
<xsl:param name="schoolname"></xsl:param>
<xsl:param name="accred"></xsl:param>

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

<xsl:template match="BodyText/Title">
	<xsl:if test="../@sycampusid=$sycampusid">
	<tr><td class="header">
		<xsl:value-of select="."/>
	</td></tr>
	</xsl:if>
</xsl:template>

<xsl:template match="BodyText/Paragraph">
	<tr><td class="bodyText">
	<xsl:if test="../@sycampusid=$sycampusid">
	<xsl:variable name="newstring2">
		<xsl:variable name="newstring">
			<xsl:call-template name="globalReplace">
			<xsl:with-param name="outputString" select="."/>
			<xsl:with-param name="target"
select="'#schoolname#'"/>
			<xsl:with-param name="replacement"
select="$schoolname"/>
			</xsl:call-template>	
		</xsl:variable>
		<xsl:call-template name="globalReplace">
			<xsl:with-param name="outputString"
select="$newstring"/>
			<xsl:with-param name="target"
select="'#accred#'"/>
			<xsl:with-param name="replacement"
select="$accred"/>
		</xsl:call-template>
	</xsl:variable>
		<xsl:call-template name="globalReplace">
			<xsl:with-param name="outputString"
select="$newstring2"/>
			<xsl:with-param name="target"
select="'&amp;quot'"/>
			<xsl:with-param name="replacement"
select="'&amp;#8217'"/>
		</xsl:call-template>
	</xsl:if>
	</td></tr>
</xsl:template>

<xsl:template match="BodyText/Link">
	<xsl:if test="../@sycampusid=$sycampusid">
	<tr><td class="bodyText">
	<a><xsl:attribute
name="class">bodytextlink</xsl:attribute><xsl:attribute
name="href"><xsl:value-of
select="./@linktarget"/></xsl:attribute><xsl:value-of
select="."/></a><xsl:text>&#160;</xsl:text>

	<xsl:call-template name="globalReplace">
		<xsl:with-param name="outputString"
select="./@linktext"/>
		<xsl:with-param name="target" select="'#schoolname#'"/>
		<xsl:with-param name="replacement"
select="$schoolname"/>
	</xsl:call-template>	
	</td></tr>
	</xsl:if>
</xsl:template>
		
<xsl:template name="globalReplace">
  <xsl:param name="outputString"/>
  <xsl:param name="target"/>
  <xsl:param name="replacement"/>
  <xsl:choose>
    <xsl:when test="contains($outputString,$target)">
      <xsl:value-of
select="concat(substring-before($outputString,$target), $replacement)"/>
      <xsl:call-template name="globalReplace">
        <xsl:with-param name="outputString"
select="substring-after($outputString,$target)"/>
        <xsl:with-param name="target" select="$target"/>
        <xsl:with-param name="replacement" select="$replacement"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$outputString"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread