XSLT - Date condition

I have date fields that are defined optional in my schema.

If element exists - I want to check for empty string, if it is empty then not put the field in the output XML.

If it as some value then carry the date to output XML.

I need to write XSLT (Version 1.0)

Any Idea?

Thanks
LVL 8
mani_saiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
the test to check if the element exists (element name assumed "foo")

xsl:if test="foo"

the test to check if the element is the empty string

xsl:if test="nort(normalize-space(foo))"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mani_saiAuthor Commented:
Thanks

what is nort...
0
Geert BormansInformation ArchitectCommented:
should be "not()"
sorry, typo
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mani_saiAuthor Commented:
is it typo..

xsl:if test="not(normalize-space(foo))"
0
Geert BormansInformation ArchitectCommented:
many try to use string-length(normalize-space()) = 0, but you don't have to,
an empty string returns false() in a boolean expression,
so the string-length = 0 is overhead
0
mani_saiAuthor Commented:
Thanks. I came up with this....

<xsl:if test="not(normalize-space(CODINGDATE2))">
 <xsl:element name="CodingDate2">
<xsl:value-of select="normalize-space(CODINGDATE2)" disable-output-escaping="yes"/>
</xsl:element>
</xsl:if>
0
mani_saiAuthor Commented:
oops.. i got it wrong...

This one works...


<xsl:if test="normalize-space(CODINGDATE2)">
 <xsl:element name="CodingDate2">
<xsl:value-of select="normalize-space(CODINGDATE2)" disable-output-escaping="yes"/>
</xsl:element>
</xsl:if>
0
mani_saiAuthor Commented:
Gertone,
When you get chance can you please take a look at it...

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_28264018.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.