[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: constructing an element with an element's content

Subject: Re: 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
Re:  constructing an element with an element's content
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.