Re: [xsl] Needed String Split with children

Subject: Re: [xsl] Needed String Split with children
From: Mitch Amiano <mitch.amiano@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 27 Oct 2002 17:23:00 -0500
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=""; version="1.0">

<xsl:template match="/Books">
     <xsl:apply-templates select="@*|node()"/>

<xsl:template match="FLD">
     <xsl:apply-templates select="@*"/>
     <xsl:for-each select="node()|text()">
        <xsl:when test="node()">
              <xsl:apply-templates select="@*|node()"/>
        <xsl:when test="position() != last()">
              <xsl:value-of select="."/>
        <xsl:when test="string-length(normalize-space()) &gt; 5">
           <xsl:variable name="laststring" select="normalize-space()"/>
           <xsl:variable name="yearstring" select="substring( $laststring, string-length($laststring)-4, 4)"/>
           <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)"/>
              <xsl:value-of select="$yearstring"/>
              <xsl:value-of select="."/>

<xsl:template match="*">
<xsl:apply-templates select="@*|node()"/>

Mike Ferrando wrote:

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.


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.

Mike Ferrando
Washington, DC

Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site

XSL-List info and archive:

XSL-List info and archive:

Current Thread