Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Fri, 11 Jul 2008 02:12:34 -0700 (PDT),    group: microsoft.public.xsl        back       


Copy source to translation when type equals unfinished   
Hi,

I have the following XML file:


<TS>
 <context>
  <name>ElementName</name>
  <message>
   <location line="16" filename="build/debug/xslt/
xml_ApplicationDefaults.cpp" />
   <source>Application</source>
   <translation>Programm</translation>
  </message>
  <message>
   <location line="24" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Archive hierarchy</source>
   <translation type="unfinished" />
  </message>
  <message>
   <location line="18" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Folder</source>
   <translation>Ordner</translation>
  </message>
  <message>
   <location line="28" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job assembler</source>
   <translation type="unfinished" />
  </message>
  <message>
   <location line="26" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job dismantler</source>
   <translation>Jobs zerlegen</translation>
  </message>
</context>
</TS>


To process this file in our translation environment I would need an
XSL transformation that copies this file with the following change:
whenever the attribute type of the element translation equals
unfinished, I want the content of the element source copied to the
element target.


So the desired output would look like this:


<TS>
 <context>
  <name>ElementName</name>
  <message>
   <location line="16" filename="build/debug/xslt/
xml_ApplicationDefaults.cpp" />
   <source>Application</source>
   <translation>Programm</translation>
  </message>
  <message>
   <location line="24" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Archive hierarchy</source>
   <translation type="unfinished">Archive hierarchy</translation>
  </message>
  <message>
   <location line="18" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Folder</source>
   <translation>Ordner</translation>
  </message>
  <message>
   <location line="28" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job assembler</source>
   <translation type="unfinished">Job assembler</translation>
  </message>
  <message>
   <location line="26" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job dismantler</source>
   <translation>Jobs zerlegen</translation>
  </message>
</context>
</TS>


I recycled a previous XSLT but this doesn't quite produce the right
output:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <xsl:output indent="yes" encoding="UTF-8"/>
        <xsl:template match="*">
                <xsl:call-template name="createNode"/>
        </xsl:template>


        <xsl:template name="createNode">
                <xsl:variable name="tagName">
                        <xsl:value-of select="local-name()"/>
                </xsl:variable>
                <xsl:choose>
                        <xsl:when test="$tagName = 'translation'">
                                <xsl:element name="translation">
                                        <xsl:attribute name="type">
                                                <xsl:value-of
select="./@type"/>
                                        </xsl:attribute>


                                        <xsl:value-of select="../
source"/>


                                        <xsl:for-each select="./*">
                                                <xsl:call-template
name="createNode"/>
                                        </xsl:for-each>
                                </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:element name="{$tagName}">
                                        <xsl:if test="count(./*) =
0">
                                                <xsl:value-of
select="."/>
                                        </xsl:if>


                                        <xsl:for-each select="./*">
                                                <xsl:call-template
name="createNode"/>
                                        </xsl:for-each>
                                </xsl:element>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>
</xsl:stylesheet>


Thanks!
Thomas
date: Fri, 11 Jul 2008 02:12:34 -0700 (PDT)   author:   Thomas

Re: Copy source to translation when type equals unfinished   
Thomas wrote:

> To process this file in our translation environment I would need an
> XSL transformation that copies this file with the following change:
> whenever the attribute type of the element translation equals
> unfinished, I want the content of the element source copied to the
> element target.
> 
> 
> So the desired output would look like this:
> 
> 
> <TS>
>  <context>
>   <name>ElementName</name>
>   <message>
>    <location line="16" filename="build/debug/xslt/
> xml_ApplicationDefaults.cpp" />
>    <source>Application</source>
>    <translation>Programm</translation>
>   </message>
>   <message>
>    <location line="24" filename="build/debug/xslt/
> xml_ElementsPaneLayout_PS.cpp" />
>    <source>Archive hierarchy</source>
>    <translation type="unfinished">Archive hierarchy</translation>

I don't see any element named 'target' in the output, rather the 
contents of the 'source' element is copied to the 'translation' element.

The following stylesheet does that:

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

   <xsl:template match="@* | node()">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="message/translation[@type = 'unfinished']">
     <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:value-of select="../source"/>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Fri, 11 Jul 2008 13:41:40 +0200   author:   Martin Honnen

Re: Copy source to translation when type equals unfinished   
Hi,

Sorry, you're right, I meant the 'translation' element instead of
'target' element.

Thanks a lot for the quick response. Works like a charm.

Thomas

On 11 jul, 13:41, Martin Honnen  wrote:
> Thomas wrote:
> > To process this file in our translation environment I would need an
> > XSL transformation that copies this file with the following change:
> > whenever the attribute type of the element translation equals
> > unfinished, I want the content of the element source copied to the
> > element target.
>
> > So the desired output would look like this:
>
> > <TS>
> >  <context>
> >   <name>ElementName</name>
> >   <message>
> >    <location line="16" filename="build/debug/xslt/
> > xml_ApplicationDefaults.cpp" />
> >    <source>Application</source>
> >    <translation>Programm</translation>
> >   </message>
> >   <message>
> >    <location line="24" filename="build/debug/xslt/
> > xml_ElementsPaneLayout_PS.cpp" />
> >    <source>Archive hierarchy</source>
> >    <translation type="unfinished">Archive hierarchy</translation>
>
> I don't see any element named 'target' in the output, rather the
> contents of the 'source' element is copied to the 'translation' element.
>
> The following stylesheet does that:
>
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
>
>    <xsl:template match="@* | node()">
>      <xsl:copy>
>        <xsl:apply-templates select="@* | node()"/>
>      </xsl:copy>
>    </xsl:template>
>
>    <xsl:template match="message/translation[@type = 'unfinished']>      <xsl:copy>
>        <xsl:apply-templates select="@*"/>
>        <xsl:value-of select="../source"/>
>      </xsl:copy>
>    </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
date: Fri, 11 Jul 2008 05:17:56 -0700 (PDT)   author:   Thomas

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us