xsl-list
[Top] [All Lists]

Re: [xsl] How to expand a string

2006-08-30 04:19:40


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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>