Re: [xsl] How to expand a string

Subject: Re: [xsl] How to expand a string
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 30 Aug 2006 12:19:25 +0100
> but I am stuck in the 1.0 world;


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
<xsl:template match="w">
was: <xsl:value-of select="."/>
now: <xsl:call-template name="decamel"/> 
</xsl:template>

<xsl:template name="decamel">
  <xsl:param name="s" select="."/>
  <xsl:variable name="a" select="substring($s,1,1)"/>
  <xsl:if test="not(translate($a,'QWERTYUIOPASDFGHJKLZXCVBNM',''))">
    <xsl:text> </xsl:text>
  </xsl:if>
  <xsl:value-of select="$a"/>
  <xsl:if test="string-length($s)&gt;1">
    <xsl:call-template name="decamel">
      <xsl:with-param name="s" select="substring($s,2)"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>
</xsl:stylesheet>


<x>
<w>FailedCriteria</w>
<w>NoSampleDetected</w>
<w>OutsideOfCalibrationRange</w>
<w>DetectorOverRange</w>
</x>


$ saxon camel.xml camel.xsl
<?xml version="1.0" encoding="utf-8"?>

was: FailedCriteria
now:  Failed Criteria

was: NoSampleDetected
now:  No Sample Detected

was: OutsideOfCalibrationRange
now:  Outside Of Calibration Range

was: DetectorOverRange
now:  Detector Over Range


(with a bit of extra work you could avoid putting a space in front of
leading capitals as well)

David

Current Thread