Subject: Re: Needed String Split with children
From: Mike Ferrando <mikeferrando@xxxxxxxxx>
Date: Tue, 29 Oct 2002 06:34:06 -0800 (PST)
|
Mitch,
Thanks, This looks interesting.
Mike Ferrando
Washington, DC
--- Mitch Amiano <mitch.amiano@xxxxxxxxxxxxxxxxxxxx> wrote:
> Do you want to retain the <I> and/or other elements which may
> be present in the input XML when you tag the year with <UNITDATE>?
>
> You could loop over the children of <FLD> and parse only the last
> string if it ends in a numeric year as expected, copying other
> nodes
> straight through if not.
>
> Does this do what you need?
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:template match="/Books">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="FLD">
> <xsl:copy>
> <xsl:apply-templates select="@*"/>
> <xsl:for-each select="node()|text()">
> <xsl:choose>
> <xsl:when test="node()">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:when>
> <xsl:when test="position() != last()">
> <xsl:value-of select="."/>
> </xsl:when>
> <xsl:when test="string-length(normalize-space()) > 5">
> <xsl:variable name="laststring"
> select="normalize-space()"/>
> <xsl:variable name="yearstring" select="substring(
> $laststring, string-length($laststring)-4, 4)"/>
> <xsl:choose>
> <xsl:when test="translate( $yearstring, '0123456789',
> '0123456789') = $yearstring">
> <xsl:message>Translate worked: '<xsl:value-of
> select="$yearstring"/>'</xsl:message>
> <xsl:value-of select="substring( $laststring, 1,
> string-length($laststring)-5)"/>
> <UNITDATE>
> <xsl:value-of select="$yearstring"/>
> </UNITDATE>
> <xsl:text>.</xsl:text>
> </xsl:when>
> </xsl:choose>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="."/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="*">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()"/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> Mike Ferrando wrote:
>
> >Friends,
> >I have been holding off on this question, but I find myself
> >confronting it more and more. I have not really figured out how to
> >get around it. So I have instead tagged the string I wanted to
> split
> >when the string is in a node with children.
> >
> >What I would like is to split a string, but then be able to either
> >replace the children as nodes, or to replace the coded string that
> I
> >split off.
> >
> >I have created a template to capture the last part of each string
> and
> >render it. However, I cannot figure out how to rebuild the rest of
> >the string with its original children, nor how to replace the
> string
> >I have now captured and coded.
> >
> >XML:
> >
> >Calvin, John. /The Bondage and Liberation of the Will/.
> >Baker Books, Inc., 1996.
> >Deissmann, Adolf. /Light from the Ancient East/. George A.
> >Doran, Co., 1927.
> >Lightfoot, J. B. /Notes on the 1^st four Epistles of
> >Saint Paul./ Hendrikson Publishers, Inc., 1995.
> >
> >
> >My output:
> >
> >Calvin, John. The Bondage and Liberation of the Will. Baker
> >Books, Inc., 1996.
> >Deissmann, Adolf. Light from the Ancient East. George A. Doran,
> >Co., 1927.
> >Lightfoot, J. B. Notes on the 1st four Epistles of Saint Paul.
> >Hendrikson Publishers, Inc., 1995.
> >
> >
> >This example is rather simplified, but the need is still the same.
> >
> >Thanks,
> >Mike Ferrando
> >Washington, DC
> >
> >__________________________________________________
> >Do you Yahoo!?
> >Y! Web Hosting - Let the expert host your web site
> >http://webhosting.yahoo.com/
> >
> > XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
> >
> >
>
>
>
> XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
>
__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|