This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: RE: Next node name
- From: "Casadome, Francisco Javier" <Francisco dot Casadome at bowneglobal dot es>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 4 Apr 2002 04:32:32 +0200
- Subject: RE: [xsl] RE: Next node name
- Reply-to: xsl-list at lists dot mulberrytech dot com
Here's the best solution I have found so far:
Short TMX version:
<?xml version="1.0" ?>
<tmx version="version 1.1">
<body>
<tu usagecount="1" creationdate="20020403T170925Z" creationid="FRANK">
<tuv lang="EN-US">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>.</seg>
</tuv>
</tu>
<tu usagecount="1" creationdate="20020403T170925Z" creationid="FRANK">
<tuv lang="EN-US">
<seg>Click <ut>{\b </ut>Properties<ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\b </ut>Properties<ut>}</ut>.</seg>
</tuv>
</tu>
<tu usagecount="1" creationdate="20020403T170925Z" creationid="FRANK">
<tuv lang="EN-US">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>, and then click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>OK<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>, and then click <ut>{\cs6\f1\cf6\lang1024
</ut><B><ut>}</ut>OK<ut>{\cs6\f1\cf6\lang1024
</ut></B><ut>}</ut>.</seg>
</tuv>
</tu>
<tu usagecount="1" creationdate="20020403T170925Z" creationid="FRANK">
<tuv lang="EN-US">
<seg>Click <ut>{\b </ut>Properties<ut>}</ut>, and the click <ut>{\b
</ut>OK<ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\b </ut>Properties<ut>}</ut>, and the click <ut>{\b
</ut>OK<ut>}</ut>.</seg>
</tuv>
</tu>
</body>
</tmx>
And the XSL... It's quite complicated and not very beautiful but it seems to
work... You can try transforming and see the results.
Any improvement at first glance ?
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace" version="1.0">
<msxsl:script language="VBScript" implements-prefix="user"><![CDATA[
function Rep(str, strout, strin)
Rep = Replace(str,strout,strin)
end function
]]></msxsl:script>
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"
encoding="UTF-8"/>
<xsl:template match="/">
<Patterns>
<xsl:for-each select="tmx/body/tu/tuv[1]/seg[ut]">
<xsl:sort select="text()" order="ascending"
data-type="text"/>
<xsl:call-template name="Discard">
<xsl:with-param name="txt">
<xsl:call-template name="CleanVARS">
<xsl:with-param name="txt">
<xsl:apply-templates
select="node()" mode="seg"/>
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</Patterns>
</xsl:template>
<xsl:template match="*" mode="seg">
<xsl:text>(%VAR%)</xsl:text>
</xsl:template>
<xsl:template match="text()" mode="seg">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="not(contains(.,'>') and
contains(.,'<'))">
<xsl:value-of select="."/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="CleanVARS">
<xsl:param name="txt"/>
<xsl:param name="VAR">0</xsl:param>
<xsl:if test="$txt!=''">
<xsl:choose>
<xsl:when test="contains($txt,'(%VAR%)(%VAR%)')">
<xsl:call-template name="CleanVARS">
<xsl:with-param name="txt">
<xsl:value-of
select="user:Rep(string($txt),'(%VAR%)(%VAR%)','(%VAR%)')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($txt,'(%VAR%)')">
<xsl:choose>
<xsl:when
test="starts-with(txt,'(%VAR%)')">
<xsl:call-template
name="CleanVARS">
<xsl:with-param
name="txt">
<xsl:value-of select="substring-after($txt,'(%VAR%)')"/>
</xsl:with-param>
<xsl:with-param
name="VAR" select="1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when
test="$VAR=1">
<xsl:text>(%VAR%)</xsl:text>
<xsl:call-template name="CleanVARS">
<xsl:with-param name="txt">
<xsl:value-of select="substring-after($txt,'(%VAR%)')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($txt,'(%VAR%)')"/>
<xsl:call-template name="CleanVARS">
<xsl:with-param name="txt">
<xsl:value-of select="substring-after($txt,'(%VAR%)')"/>
</xsl:with-param>
<xsl:with-param name="VAR" select="1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$txt"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- this template just discards not useful <seg> -->
<xsl:template name="Discard">
<xsl:param name="txt"/>
<xsl:variable name="st" select="substring($txt,1,1)"/>
<xsl:if test="contains($txt,'(%VAR%)')">
<xsl:if test="$st =
translate($st,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')">
<xsl:if
test="contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',$st)">
<Pattern>
<xsl:value-of select="$txt"/>
</Pattern>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list