Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] how to avoid generating an < empty element />

From: Manuel Souto Pico <manuel.souto@-------------->
To:
Date: 2/5/2009 10:00:00 AM
ERRATA:



Where it says 'the part in red' it should say 'the term entry 5383'. 
I've just realized I can't use colours in my mails ;)



Thanks, Manuel



Manuel Souto Pico escribis:
Hi,



I'm not experienced at all with XSLT and I've got one question 
relative to a <xsl:if test... > element which tests whether the 
element is a duplicate or not. Looking at my output you could get an 
idea of what I've managed to do:



<?xml version="1.0" encoding="UTF-8"?>

<martif type="TBX" xml:lang="en">

  <martifHeader>

     <fileDesc>

        <sourceDesc>

           <p/>

        </sourceDesc>

     </fileDesc>

  </martifHeader>

  <text>

     <body>

        <termEntry id="2107">

           <langSet lang="spa-es">

              <ntig>

                 <termGrp>

                    <term>Calibracisn</term>

                    <termNote type="termType">full form</termNote>

                    <termNote type="TS_CreateId">Alexandra 
M|tzel</termNote>

                    <termNote type="TS_UpdateId">Alexandra 
M|tzel</termNote>

                    <date type="origination">20070420T093242Z</date>

                    <date type="modification">20070420T093242Z</date>

                    <term>Calibramiento</term>

                    <termNote type="termType">full form</termNote>

                    <termNote type="TS_CreateId">Alexandra 
M|tzel</termNote>

                    <termNote type="TS_UpdateId">Alexandra 
M|tzel</termNote>

                    <date type="origination">20070420T093242Z</date>

                    <date type="modification">20070420T093242Z</date>

                 </termGrp>

              </ntig>

           </langSet>

        </termEntry>

        <termEntry id="5383">

           <langSet lang="spa-es">

              <ntig>

                 <termGrp/>

              </ntig>

           </langSet>

        </termEntry>

     </body>

  </text>

</martif>



Within the <termGrp> element, the xsl:if tests whether it is the first 
time that the content of the tag <element> is processed or not. If 
it's the first one, it outputs the whole contents of the <termGrp> 
element, as in the termEntry 2107. Else, it doesn't output them (like 
in entry 5383). I think I'm using what is called Muenchian method. So 
far so good.



This would be good enough for me but I need to do something else, 
which is: if the term is not new (i.e. it has been processed and 
output before), I would like the whole entry to not appear in the 
oupput, meaning that the part in red shouldn't exist in my output. I 
can do this with some postediting of my output but I thought that, if 
possible, it would ideal to do it also with the same xsl template. Do 
you know how to do this?



This is my code, in case you want to check, and my input data (sorry 
for making the email so long):



<?xml version="1.0" encoding="UTF-8"?>

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

   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

   <xsl:key name="spa-term" 
match="text/body/termEntry/langSet[@lang='spa-es']/ntig/termGrp/term" 
use="."/>

   <xsl:template match="/">

       <martif type="TBX" xml:lang="en">

           <martifHeader>

               <fileDesc>

                   <sourceDesc>

                       <p></p>

                   </sourceDesc>

               </fileDesc>

           </martifHeader>

           <text>

               <body>

                   <xsl:for-each select="martif/text/body/termEntry">

                       <termEntry>

                           <xsl:attribute name="id">

                               <xsl:value-of select="@id"/>

                           </xsl:attribute>

                       <!--    <xsl:value-of select="current()"/> -->

                           <langSet lang="spa-es"><ntig><termGrp>

                               <xsl:for-each 
select="langSet[@lang='spa-es']/ntig/termGrp/term">

                                   <xsl:if test="generate-id(.) =

                                       generate-id(key('spa-term', 
.)[1]) ">

                                       <term>

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

                                       </term>

                                       <xsl:for-each 
select="../termNote">

                                           <termNote>

                                               <xsl:attribute 
name="type">

                                                   <xsl:value-of 
select="@type"/>

                                               </xsl:attribute>

                                               <xsl:value-of 
select="current()"/>

                                           </termNote>

                                       </xsl:for-each>

                                       <xsl:for-each select="../date">

                                           <date>

                                               <xsl:attribute 
name="type">

                                                   <xsl:value-of 
select="@type"/>

                                               </xsl:attribute>

                                               <xsl:value-of 
select="current()"/>

                                           </date>

                                       </xsl:for-each>  
                                   </xsl:if>

                               </xsl:for-each>

                           </termGrp></ntig></langSet>  
                                                </termEntry>

                   </xsl:for-each>                                  
</body>

           </text>

       </martif>

   </xsl:template>

</xsl:stylesheet>




__DATA:



<?xml version='1.0' encoding='UTF-8'?>



<martif type="Part2v1" lang="en">

   <martifHeader>

       <fileDesc>

           <titleStmt>

               <title>Transit XV TermStar export file</title>

           </titleStmt>

           <publicationStmt>

               <p/>

           </publicationStmt>

           <sourceDesc>

               <p>TermStar dictionary</p>

           </sourceDesc>

       </fileDesc>

       <encodingDesc>

           <p type="DatCatSetName">maxi-set</p>

           <p type="DatCatSetVersion">1</p>

       </encodingDesc>

       <revisionDesc>

           <change>

               <p>20090203T115345Z</p>

           </change>

       </revisionDesc>

       <databaseDesc>

           <p type="TS_DictName">Leica_LAS-SW_DEU_REF</p>

           <p type="TS_DataBase">Leica</p>

           <p type="TS_DictImagePath" mode="AbsolutePaths"/>

           <p type="TS_DictProperty" id="ExportedLangs" 
val="0">DEU,ESP</p>

           <p type="TS_DictProperty" id="ExtractedDataBase" 
val="0">Leica_LAS_2007</p>

           <p type="TS_DictProperty" id="ExtractedDictName" 
val="0">Software_LAS_new</p>

           <p type="TS_DictProperty" id="ExtractTime" 
val="0">20080407T163925Z</p>

           <p type="TS_DictProperty" id="GUID" 
val="0">{83666734-317B-4E46-B445-6E9901523869}</p>

           <p type="TS_DictProperty" id="MainLang" val="0">deu-de</p>

           <p type="TS_DictProperty" id="OriginalDatabaseGUID" val="0"

               >{FBADCF63-B2A3-492F-9B32-B330A0D12477}</p>

       </databaseDesc>

   </martifHeader>

   <text>

       <body>

           <termEntry id='2107'>

               <note type='TS_Subject'>Terminologie</note>

               <note type='TS_CreateId'>Alexandra M|tzel</note>

               <date type='origination'>20070420T093242Z</date>

               <note type='TS_UpdateId'>Alexandra M|tzel</note>

               <date type='modification'>20070420T093242Z</date>

                            <langSet lang='deu-de'>

                   <ntig><termGrp>

                       <term>Kalibrierung</term>

                       <termNote type='termType'>full form</termNote>

                       <termNote type='TS_CreateId'>Alexandra 
M|tzel</termNote>

                       <date type='origination'>20070420T093242Z</date>

                       <termNote type='TS_UpdateId'>Alexandra 
M|tzel</termNote>

                       <date type='modification'>20070420T093242Z</date>

                   </termGrp></ntig>

                                </langSet>

                            <langSet lang='spa-es'>

                   <ntig><termGrp>

                       <term>Calibracisn</term>

                       <termNote type='termType'>full form</termNote>

                       <termNote type='TS_CreateId'>Alexandra 
M|tzel</termNote>

                       <date type='origination'>20070420T093242Z</date>

                       <termNote type='TS_UpdateId'>Alexandra 
M|tzel</termNote>

                       <date type='modification'>20070420T093242Z</date>

                   </termGrp></ntig>

                                    <ntig><termGrp>

                       <term>Calibramiento</term>

                       <termNote type='termType'>full form</termNote>

                       <termNote type='TS_CreateId'>Alexandra 
M|tzel</termNote>

                       <date type='origination'>20070420T093242Z</date>

                       <termNote type='TS_UpdateId'>Alexandra 
M|tzel</termNote>

                       <date type='modification'>20070420T093242Z</date>

                   </termGrp></ntig>

               </langSet>

           </termEntry>

                             <termEntry id='5383'>

               <note type='TS_Subject'>FW4000</note>

               <note type='TS_CreateId'>Gerald Dennett</note>

               <date type='origination'>20040319T092948Z</date>

               <note type='TS_UpdateId'>susanne</note>

               <date type='modification'>20040320T224024Z</date>

                            <langSet lang='eng-gb'>

                   <ntig><termGrp>

                       <term>Calibration</term>

                       <termNote type='termType'>full form</termNote>

                       <termNote type='TS_CreateId'>Gerald 
Dennett</termNote>

                       <date type='origination'>20040319T092948Z</date>

                       <termNote type='TS_UpdateId'>susanne</termNote>

                       <date type='modification'>20081117T123010Z</date>

                       <termNote 
type='TS_PartOfSpeech'>lblCalibration</termNote>

                       <descrip 
type='context'>Rainbow_frmEnterItems</descrip>

                       <termNote type='TS_Source'>September 
2003</termNote>

                   </termGrp></ntig>

                                </langSet>

                            <langSet lang='spa-es'>

                   <ntig><termGrp>

                       <term>Calibracisn</term>

                       <termNote type='termType'>full form</termNote>

                       <termNote type='TS_CreateId'>Gerald 
Dennett</termNote>

                       <date type='origination'>20040319T092948Z</date>

                       <termNote type='TS_UpdateId'>susanne</termNote>

                       <date type='modification'>20081117T123010Z</date>

                       <termNote 
type='TS_PartOfSpeech'>lblCalibration</termNote>

                       <descrip 
type='context'>Rainbow_frmEnterItems</descrip>

                       <termNote type='TS_Source'>September 
2003</termNote>

                   </termGrp></ntig>

                                </langSet>

           </termEntry>

       </body>

   </text>

</martif>




Thank you so much for your potential help and your attention.
Best regards,


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent