[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Ignoring an empty child


Subject: Re: [xsl] Ignoring an empty child
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Sat, 8 Sep 2012 03:10:20 -0700

Please ignore my question - I was not running the correct code.
Sorry for the noise.
Mark

-----Original Message----- From: Mark
Sent: Saturday, September 08, 2012 3:06 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Ignoring an empty child


In some <Article> elements, the <Comment> element is empty (usually it
contains another <Article> element or set of <Article> elements. When
<Comment> is empty, I want to bypass the transformations done in the Comment
template below. I cannot seem to get the code to ignore empty <Comment>
elements.

Input:
<Article>
         <Person>Gerald M. van Zanten</Person>
         <Title>New issues: Slovakia</Title>
         <IssueName>Sep/Oct</IssueName>
         <IssueNumber>5</IssueNumber>
         <Year>2007</Year>
         <Page>37</Page>
         <Comment/> <!-- WHEN EMPTY ELEMENT MATCHED, IGNORE
</Article>

Template:
<xsl:template match="Comment">
  <xsl:if test="not(empty(.))"> <!-- THIS DOES NOT SEEM TO WORK
<!-- <xsl:if test="Article"> NOR DOES THIS -->
  <span class="comment">
    <xsl:text> {Comment: </xsl:text>
    <xsl:for-each-group select="Article" group-by="Person">
      <xsl:sort select="Year"></xsl:sort>
      <xsl:sort select="IssueNumber" data-type="number"></xsl:sort>
      <xsl:sort select="Page"></xsl:sort>
      <xsl:sort select="Title" collation="{$sorting-collation}"></xsl:sort>
      <!-- <xsl:sort select="Person"
collation="{$sorting-collation}"></xsl:sort> -->
      <xsl:if test="not(Title eq preceding-sibling::Article[1]/Title)">
        <span class="comment-title">
          <xsl:apply-templates select="Title"></xsl:apply-templates>
        </span>
      </xsl:if>
      <xsl:apply-templates select="Person"></xsl:apply-templates>
      <!--and for each citation-->
      <!-- Dump duplicate citations for 1939-1999 data -->
      <xsl:if test="not(. eq preceding-sibling::Article[1])">
        <xsl:call-template name="citation"></xsl:call-template>
      </xsl:if>
    </xsl:for-each-group>
    <xsl:text>} </xsl:text>
  </span>
  </xsl:if>
</xsl:template>


Current Thread