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

Re: Transformation of hierarchy, changing levels, and.

Subject: [xsl] Re: Transformation of hierarchy, changing levels, and... back
From: Marcin Miłkowski <milek_pl@xxxxx>
Date: Wed, 03 Aug 2005 17:03:49 +0200
xliff xsl
Hi,

sorry for being imprecise. I tried to use my abbreviated notation and
that was a big mistake. However, it seems to me I found a solution.

Are the parenthetical expressions meant to appear in the output
document or are they there to illustrate the relationship between the
elements in the input document and the elements in the output
document?

Yes, exactly this is what I meant.


I'm quoting my stylesheet below (with some irrelevant sections deleted), I hope you can comment on whether I'm using efficient methods or not. I know it still does not look elegant

I have two other stylesheets which use same ids on g element (ids get generated here by <xml:number count="Tu/Tuv/node()" level="any"/>) to merge the target xml back to its source format. They are however XSLT 2.0 because I had to use charmaps to get rid of some unnecessary entity resolution. It almost works on Saxon (there are still minor glitches on the final merging stylesheets).

Thanks for any comments or suggestion.

Cheers,
	Marcin

************************************************

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">

<xsl:output method="xml" encoding="utf-8" indent="no" doctype-public="-//XLIFF//DTD XLIFF//EN"

doctype-system="http://www.oasis-open.org/committees/xliff/documents/xliff.dtd"/>
	
 <xsl:param name="Src">en-US</xsl:param>
 <xsl:param name="Trg"></xsl:param>

<xsl:template match="text()"/>

 <xsl:template match="TRADOStag">
   <xliff version="1.0" xml:lang="en">
   <xsl:element name="file">
   <xsl:attribute name="original">TMX-file.tmx</xsl:attribute>
   <xsl:attribute name="source-language">
	<xsl:value-of select="$Src"/>
    </xsl:attribute>
    <xsl:attribute name="target-language">
           <xsl:value-of select="$Trg"/>
    </xsl:attribute>
    <xsl:attribute name="datatype">TTX document</xsl:attribute>
    <header>
    <skl>
    <external-file href="skeleton.skl" />
    </skl>
    </header>
    <xsl:choose>
     <xsl:when test="//Tu"/>
      <xsl:otherwise>
      <xsl:message terminate="yes">
        Error: This TTX file is not bilingual, cannot proceed!
        You have to use a monolingual filter with a segmenter.
      </xsl:message>
    </xsl:otherwise>
    </xsl:choose>
   <body>
          <xsl:apply-templates/>
   </body>
     </xsl:element>
  </xliff>
</xsl:template>

 <xsl:template match="//Tu">
   <xsl:element name="trans-unit">
    <xsl:attribute name="id">
         <xsl:value-of select="generate-id()"/>
    </xsl:attribute>
	<xsl:apply-templates/>
   </xsl:element>
</xsl:template>

<xsl:template match="//Tuv">
<xsl:if test="@Lang=$Src">
<source>
	<xsl:apply-templates/>
</source>
</xsl:if>
 <xsl:if test='@Lang=$Trg'>
	<xsl:element name="target">
	
	 <xsl:apply-templates/>
	
	</xsl:element>
</xsl:if>	
 <xsl:if test='@Lang!=$Src and @Lang!=$Trg'>
	<xsl:element name="alt-trans">
		<xsl:element name="target">
		<xsl:attribute name="xml:lang"><xsl:value-of select="@lang"/>
		</xsl:attribute>
		<xsl:apply-templates/>
		</xsl:element>
	</xsl:element>
</xsl:if>
</xsl:template>

<xsl:template match="//Tu/Tuv/df">
<xsl:element name="g">
		<xsl:attribute name="id">
			<xsl:value-of select="generate-id()"/>
		</xsl:attribute>
		<xsl:attribute name="ts">
			<xsl:for-each select="@*">
				<xsl:text>x-df-contents:</xsl:text>
				<xsl:value-of select="name(.)"/>
				<xsl:text>=</xsl:text><xsl:value-of select="."/>
				<xsl:text>;</xsl:text>
			</xsl:for-each>
		</xsl:attribute>
	</xsl:element>
	<xsl:apply-templates/>
	<xsl:element name="g">
		<xsl:attribute name="ts">x-skl-snip</xsl:attribute>
		<xsl:attribute name="id">
		<xsl:number count="Tu/Tuv/node()" level="any"/>
		</xsl:attribute>
	</xsl:element>
		<xsl:value-of select="./text()"/>
		
	<xsl:element name="g">
	<xsl:attribute name="id">
			<xsl:value-of select="generate-id()"/>
		</xsl:attribute>
	</xsl:element>
</xsl:template>

<xsl:template match="//Tu/Tuv/ut | //Tu/Tuv/df/ut">
	<xsl:element name="ph">
		<xsl:attribute name="id">
			<xsl:value-of select="generate-id()"/>
		</xsl:attribute>
		<xsl:value-of select="./text()"/>
	</xsl:element>
</xsl:template>

<xsl:template match="//Tu/Tuv/text()">
<xsl:element name="g">
<xsl:attribute name="ts">x-skl-snip</xsl:attribute>
<xsl:attribute name="id">
	<xsl:number count="Tu/Tuv/node()" level="any"/>
	</xsl:attribute>
</xsl:element>
	<xsl:value-of select="."/>
</xsl:template>


</xsl:stylesheet>


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.