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 2:43:00 PM
Thank you so much, David,



Your code helps me understand what I was writing wrong (or redundantly).



As it is now, the following code outputs the langSet for Spanish only:



	<langSet lang="spa-es"><ntig><termGrp>
	 <xsl:for-each  select="$t">
	  <xsl:copy-of select="."/>
	  <xsl:copy-of select="../termNote"/>>
	  <xsl:copy-of select="../date"/>>
	 </xsl:for-each>

but ideally it should output the langSet for any language, so I tried 
replacing the code above with



               <xsl:for-each select="langSet">
                  <xsl:copy-of select="current()"/>
               </xsl:for-each>

The result seems to be good contents-wise, with the langSet for all the 
languages. However, the format is akward, with one blank line between 
every two lines of contents, what makes me thing that perhaps there's 
somethign wrong. Any suggestion for improvmenet?



Thank you very much!!
Manuel

PS The full template would be like this now:



<?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="Part2v1" lang="en">

           <martifHeader>

               <fileDesc>

                   <sourceDesc>

                       <p></p>

                   </sourceDesc>

               </fileDesc>

           </martifHeader>

           <text>

               <body>

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

                       <xsl:variable name="t" 
select="langSet[@lang='spa-es']/ntig/termGrp/term

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

                       <xsl:if test="$t">

                           <termEntry id="{@id}">

                               <xsl:for-each select="note|date">

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

                               </xsl:for-each>

                               <xsl:for-each select="langSet">

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

                               </xsl:for-each>

                             </termEntry>

                       </xsl:if>

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

           </text>

       </martif>

   </xsl:template>

</xsl:stylesheet>







David Carlisle escribis:
Just move the if test up before you create the outer element.
ehile I was there I simplified mist of the other code which seemed to be
more verbose than needed,


<?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">

      <xsl:variable name="t" select="langSet[@lang='spa-es']/ntig/termGrp/term

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

      <xsl:if test="$t">

       <termEntry id="{@id}">

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

	 <xsl:for-each  select="$t">

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

	  <xsl:copy-of select="../termNote"/>>

	  <xsl:copy-of select="../date"/>>

	 </xsl:for-each>

	</termGrp>

       </ntig>

	</langSet>  
       </termEntry>

      </xsl:if>

     </xsl:for-each>

     
    </body>

   </text>

  </martif>

 </xsl:template>

</xsl:stylesheet>



David



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is

powered by MessageLabs. 
________________________________________________________________________


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