Re: [xsl] constructing an element with an element's content based on the content of sibling element

Subject: Re: [xsl] constructing an element with an element's content based on the content of sibling element
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Mon, 11 Jun 2012 21:05:27 -0400
> don't yet understand how the empty xsl:when does it (although I've
> used it before)...but works like a charm..

Perhaps more intensive commenting will help:

  <!--
   We're going to hit this template several times in a row, once for
   each <productidentifier>. We want to print out the ISBN13 if there
   is one, and the ISBN10 if there is no ISBN13. So when we are
   called for a <productidentifier>, we have to figure out whether to
   generate output or not by looking at ourself and our siblings.
   * if we are the ISBN13 case, print out
   * if we are not the ISBN13 case, but one of our siblings is, then
     don't do anything (the ISBN13 will be printed when our sibling is
     matched by this very template)
   * if we are not the ISBN13 case, and none of our siblings are
     ISBN13, and we are the ISBN10, then print it out
   * if we are not the ISBN13 case, and none of our siblings are
     ISBN13, but we are not the ISBN10, then a warning message
  -->
  <xsl:template name="isbn" match="productidentifier">
    <xsl:choose>
      <!-- first take care of the "I am ISBN 13" case -->
      <xsl:when test="child::b221 = '15'">
        <controlfield tag="001">
          <xsl:text>ISBN13 = </xsl:text>
          <xsl:value-of select="b244"/>
        </controlfield>
      </xsl:when>
      <!-- if we've gotten this far, this is not the "I am ISBN 13" case -->
      <!-- test to see if we have a sibling that is hte ISBN 13 case;
      if so, do nothing, as this template will do the work (above) when
      it hits that sibling -->
      <xsl:when test="parent::*/child::productidentifier/child::b221 = '15'"/>
      <!-- we've gotten this far, so there is no sibling ISBN 13;
      so use ISBN 10, if that's what I am -->
      <xsl:when test="child::b221 = '02'">
        <controlfield tag="001">
          <xsl:text>ISBN10 = </xsl:text>
          <xsl:value-of select="b244"/>
        </controlfield>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>Danger, Will Robinson! a 'productidentifier' that is confusing</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Current Thread