[Home] [By Thread] [By Date] [Recent Entries]
At 2009-05-26 14:07 +0100, tom tom wrote:
I have a string containing a mix of Chinese and Latin characters, eg *|.Z'J%R+,H1N1,y7PZL. I wish to return a nodeset containing the following kind of structure:
Can anyone suggest the cleanest way to do this using XSLT 2?
. . . . . . . . . . Ken T:\ftemp>type tom.xml
<doc>?????H1N1??</doc>
T:\ftemp>call xslt2 tom.xml tom.xsl
<?xml version="1.0"
encoding="UTF-8"?><doc><other>?????</other><latin>H1N1</latin><other>??</othe
r></doc>
T:\ftemp>type tom.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><xsl:template match="text()" priority="1">
<xsl:analyze-string select="." regex="[!-~]+">
<xsl:matching-substring>
<latin><xsl:value-of select="."/></latin>
</xsl:matching-substring>
<xsl:non-matching-substring>
<other><xsl:value-of select="."/></other>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template><xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet> T:\ftemp>rem Done! -- XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



