|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Needed String Split with children
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. 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
|

Cart








