myothet
7/4/2017 - 7:53 AM

sentence_template.xml

<pre>
	<xsl:call-template name="sentence">
		<xsl:with-param name="description" select="//Item/so_remarks"></xsl:with-param>
	</xsl:call-template>
</pre>


<xsl:template name="string-insert">
<xsl:param name="description"/>
<xsl:variable name="length">
<xsl:value-of select="string-length($description)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$length &gt; '50'">
<xsl:variable name="basename">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string1" select="substring($description,1,50)"/>
<xsl:with-param name="string2" select="' '"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$basename"/>
<xsl:value-of select="'&#xA;'"/>
<xsl:value-of select="' '"/>
<xsl:value-of select="' '"/>
<xsl:call-template name="string-insert">
<xsl:with-param name="description" select="substring($description,string-length($basename)+1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$description"/>
<xsl:value-of select="'&#xA;'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="sentence">
<xsl:param name="description"/>
<xsl:choose>
<xsl:when test="contains($description, '&#xA;')">
<xsl:call-template name="string-insert">
<xsl:with-param name="description" select="substring-before($description, '&#xA;')"/>
</xsl:call-template>
<xsl:call-template name="sentence">
<xsl:with-param name="description" select="substring-after($description, '&#xA;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="string-insert">
<xsl:with-param name="description" select="$description"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="substring-before-last">
<xsl:param name="string1" select="''"/>
<xsl:param name="string2" select="''"/>
<xsl:if test="$string1 != '' and $string2 != ''">
<xsl:variable name="head" select="substring-before($string1, $string2)"/>
<xsl:variable name="tail" select="substring-after($string1, $string2)"/>
<xsl:value-of select="$head"/>
<xsl:if test="contains($tail, $string2)">
<xsl:value-of select="$string2"/>
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string1" select="$tail"/>
<xsl:with-param name="string2" select="$string2"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>