This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Empty elements


Playing with Mike Kays definition of empty elements,
http://sources.redhat.com/ml/xsl-list/2000-09/msg00598.html


<doc>
<node id="@id00"/>
<node id="id1"> </node>
<node id="id02"><!--comment--></node>
<node id="id03"><x/></node>
 </doc>

<xsl:template match="node">
  <xsl:call-template name="mt"/>
</xsl:template>

<xsl:template name="mt">
  <xsl:choose>
  <xsl:when test="not(string(.))">
    Node: <xsl:value-of select="@id"/> is  empty using string(.)&nl;
  </xsl:when>
  <xsl:when test="string(.)">
    Node: <xsl:value-of select="@id"/> is not empty using string(.)&nl;
  </xsl:when>
<xsl:otherwise>
  Otherwise 1 reached on  <xsl:value-of select="@id"/> .&nl;
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
  <xsl:when test="not(node())">
    Node: <xsl:value-of select="@id"/> has no children &nl;
  </xsl:when>
  <xsl:when test="node()">
    Node: <xsl:value-of select="@id"/> has children &nl;
  </xsl:when>
<xsl:otherwise>
  Otherwise 2 reached on  <xsl:value-of select="@id"/> .&nl;
</xsl:otherwise>
</xsl:choose>
</xsl:template>

gives
  Node: @id00 is  empty using string(.)
     Node: @id00 has no children 
 
    Node: id1 is not empty using string(.)
     Node: id1 has children 
 
    Node: id02 is  empty using string(.)
     Node: id02 has children 
 
    Node: id03 is  empty using string(.)
     Node: id03 has children 





Interesting, and quite informative.
(I'll be using this one :-)

Regards DaveP


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]