[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Literal string question
> > What I have in mind is to PULL the data from a specific field in my > XML document which has initials without a space between them. > > <CORPNAME>A.A. Peters</CORPNAME> > If all you want to do is select those elements whose string value contains a dot followed by anything other than a space, would this work? Although doubtless it could be done more efficiently... <xsl:template match="CORPNAME"> <!-- Assign value to variable with whitespace normalized --> <xsl:variable name="x" select="normalize-space(.)"/> <xsl:choose> <!-- If it contains '.' proceed with recursive template --> <xsl:when test="contains($x, '.')"> <xsl:call-template name="space-check"> <!-- Recursive template uses param of everything after the first '.' The space is concatenated to the end to ensure that if the string ends with '.' this is not reported as an initial --> <xsl:with-param name="y" select="concat(substring-after($x, '.'),' ')"/> </xsl:call-template> </xsl:when> <!-- Otherwise return no initials --> <xsl:otherwise> <name initials="false"><xsl:value-of select="."/></name> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="space-check"> <xsl:param name="y"/> <xsl:choose> <!-- If the param starts with a space, then this particular dot was not an initial. --> <xsl:when test="starts-with($y, ' ')"> <xsl:choose> <!-- If there are more occurrences of '.' then repeat procedure --> <xsl:when test="contains($y, '.')"> <xsl:call-template name="space-check"> <xsl:with-param name="y" select="substring-after($y, '.')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- No initials --> <name initials="false"><xsl:value-of select="."/></name> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!-- If the param does not start with a space, then the original string contained initials --> <name initials="true"><xsl:value-of select="."/></name> </xsl:otherwise> </xsl:choose> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|