[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: RE: Next node name

Subject: RE: RE: Next node name
From: "Casadome, Francisco Javier" <Francisco.Casadome@xxxxxxxxxxxxxx>
Date: Thu, 4 Apr 2002 04:32:32 +0200
lang1024
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>&lt;B&gt;<ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut>&lt;B&gt;<ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<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>&lt;B&gt;<ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<ut>}</ut>, and then click <ut>{\cs6\f1\cf6\lang1024
</ut>&lt;B&gt;<ut>}</ut>OK<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<ut>}</ut>.</seg>
</tuv>
<tuv lang="ES-EM">
<seg>Click <ut>{\cs6\f1\cf6\lang1024
</ut>&lt;B&gt;<ut>}</ut>Properties<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<ut>}</ut>, and then click <ut>{\cs6\f1\cf6\lang1024
</ut>&lt;B&gt;<ut>}</ut>OK<ut>{\cs6\f1\cf6\lang1024
</ut>&lt;/B&gt;<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(.,'&gt;') and
contains(.,'&lt;'))">
			<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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.