1. How do I check, in my .xsl file, if an element is empty? 2. Why do I keep getting the first element from my .xml file - I don't want it to be in my .html file. ex: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="myXsl.xsl"?> <DATE>2001-01-01</DATE> <PERSON> <NAME><![CDATA[My Name]]> </NAME> <AGE>50</AGE> <PHONE>Yes</PHONE> </PERSSON> If I write in my .xsl file: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl utput method="html"/> <xsl:template match="/"> <xsl:apply-templates select="PERSON"> </xsl:template> <xsl:template match="PERSON"> <xsl:value-of select="AGE"/> </xsl:template> I get: 2001-01-01 50 Why?? Nils
I'm a bit worried that your example is not valid XML, which could cause the XSL processor to go a bit wierd even if it does manage to parse it. You really need a single "root" element for your tree - currently you have two roots "date" and "person" (and person is not closed correctly, it has an extra "S").
1. How do I check, in my .xsl file, if an element is empty? XSLT Questions and Answers (url: )http://www.dpawson.co.uk/xsl/sect2/sect21.html) is a priceless source of information. In particular: �How to test if the value of a certain node is empty? Depends what you mean by empty. ... Contains no text content: not(string(.)) Contains no text other than whitespace: not(normalize-space(.)) ...� 2. Why do I keep getting the first element from my .xml file - I don't want it to be in my .html file. Hm. Your XML + XSL do not give any output at all on my computer... However, when I changed <xsl:apply-templates select="PERSON"> to <xsl:apply-templates select="/PERSONS/PERSON"> the output is: 50 I suspect your template for PERSON was not called. (You can check it by inserting some text after <xsl:template>: <xsl:template match="PERSON"> this is a string to indicate that this template was called <xsl:value-of select="AGE"/> ...) Instead, your XSLT processor used so-called �default templates� � special templates which have to be applied when there is no explicit template that matches an element. Default temlate simply outputs an element�s content. Of course, this begs question: why content of the PHONE element is skipped?
[This message has been edited by Mapraputa Is (edited June 11, 2001).]