[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: generate an element only if the result is not empt
Subject: Re: generate an element only if the result is not empty
From: Manuel Souto Pico <manuel.souto@xxxxxxxxxxxxxx>
Date: Tue, 25 Aug 2009 12:48:23 +0200
|
i David and Michael,
Thank you very much for your prompt reply.
You are right about node(), I had misunderstood what it does. And you
are almost right in that my requirement is to ignore any seg elements
with element content but for the time being, your proposal is good enough.
With your template I get no term element, which is good, but the
termEntry is still generated, even if there's no content inside (only
elements). So I suppose I should move your template out to use it before
I create the termEntry element. I'm try to sort that out, but if I don't
manage with XSL it's not an issue, it's easy to remove by search&replace.
I can also use strip-space or normalize-space now to remove extra
whitespace between or within elements from other parts of the file.
Thanks a lot!
Manuel
David Carlisle wrote:
The template (using select="node()" and not select=".")
<xsl:template match="seg">
<term>
<xsl:value-of select="node()" />
That's a very strange construct to use, especially in xslt 1.
node() selects all the children and then value-of discards all but the
first, which means that if there are child elements as in your example
you get just the first indentation white space if there is any, however
if the first child had not been indented you would get the string value
of the first element.
<seg>
<it></Title></it>
<bpt i="1" type="struct"><Elt type='Groupbox'
id='242' coor='0,0,412,112' style='50020007,0' class='#FF#0080'></bpt>
</seg>
produces
<term>
</term>
but
<seg><it></Title></it>
<bpt i="1" type="struct"><Elt type='Groupbox'
id='242' coor='0,0,412,112' style='50020007,0'
class='#FF#0080'></bpt></seg>
produces
<term>></Title></term>
If I understand your requirement it is to ignore any seg elements with
element content, but to make a term element for those that have non
white space text content.
so just
<xsl:apply-templates select="seg"/>
with
<xsl:template match="seg[*]"/>
<xsl:template match="seg[not(normalize-space(.))]"/>
<xsl:template match="seg">
<text><xsl:value-of select="."/></text>
</xsl:template>
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.
________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|