[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: RE: String manipulation in XSLT
Please try this stylesheet <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:common="http://exslt.org/common" version="1.0"> <xsl:output method="text" /> <xsl:variable name="str" select="'abc.def.ghi'" /> <xsl:template match="/"> <xsl:variable name="rtf"> <string> <xsl:call-template name="reform_string"> <xsl:with-param name="str" select="$str" /> <xsl:with-param name="delim" select="'.'" /> </xsl:call-template> </string> </xsl:variable> <xsl:variable name="package"> <xsl:for-each select="common:node-set($rtf)/string/part"> <xsl:if test="position() != last()"> <xsl:value-of select="." /> </xsl:if> <xsl:if test="position() < (last() - 1)"> . </xsl:if> </xsl:for-each> </xsl:variable> Package name - <xsl:value-of select="translate($package,'
 ','')" /> Class name - <xsl:value-of select="common:node-set($rtf)/string/part[last()]" /> </xsl:template> <xsl:template name="reform_string"> <xsl:param name="str" /> <xsl:param name="delim" /> <xsl:choose> <xsl:when test="contains($str,'.')"> <part><xsl:value-of select="substring-before($str,'.')" /></part> <xsl:call-template name="reform_string"> <xsl:with-param name="str" select="substring-after($str,'.')" /> <xsl:with-param name="delim" select="$delim" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <part><xsl:value-of select="$str" /></part> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> This was tested with Saxon 8.5.1 as java net.sf.saxon.Transform file.xsl file.xsl (The stylesheet filename is file.xsl) Hope you can take some ideas from this.. >I'm constantly frustrated by trying to write little templates to do these simple >things like splitting a string etc. I do enjoy writing XSLT stylesheets! If you can, you can move to XSLT 2.0. It has lot of new constructs and functions, which reduce the program size considerably. Regards, Mukul
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|