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]
Other format: [Raw text]

Re: Generating a list of items NOT present in source XML


At 11:57 AM 5/17/2002, you wrote:
>   <xsl:with-param name="count" select="count + 1" />

     [  Just for those following this thread (and later
      in the archives), the above line (and others like
      it) should probably read as
      <xsl:with-param name="count" select="$count + 1" />
      Note the dollar-sign before 'count'.  Without it,
      you will have an infinite recursion. ]

Jeni,

   I modified your code to the following stylesheet.  The first template 
matches / and calls the other template with a sorted node-set.  I have a 
question at the end of the sheet.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
extension-element-prefixes="msxsl">
   <xsl:output method="html" indent="yes"/>
   <xsl:template match="/">
     <missing>
       <xsl:variable name="sorted-obj-rtf">
         <xsl:for-each select="root/obj">
           <xsl:sort data-type="number" select="childnode"/>
           <xsl:copy-of select="."/>
         </xsl:for-each>
       </xsl:variable>
       <xsl:call-template name="show-missing">
         <xsl:with-param name="nodes" 
select="msxsl:node-set($sorted-obj-rtf)/obj"/>
         <xsl:with-param name="start-number" select="1"/>
         <xsl:with-param name="end-number" select="9"/>
         <xsl:with-param name="index" select="'./childnode'"/>
       </xsl:call-template>
     </missing>
   </xsl:template>
   <!--

   Named Template "show-missing"

   -->
   <xsl:template name="show-missing">
     <xsl:param name="nodes" select="/.."/>
     <xsl:param name="start-number" select="1"/>
     <xsl:param name="end-number" select="1"/>
     <xsl:param name="index"/>
     <xsl:if test="$nodes and $index and ($end-number >= $start-number)">
       <xsl:choose>
         <!-- For each of these tests, instead of comparing against
              $nodes[1], I would like to compare against
              $nodes[1]/($index converted to XPath path)/. -->
         <xsl:when test="$start-number > $nodes[1]">
           <xsl:call-template name="show-missing">
             <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
             <xsl:with-param name="start-number" select="$start-number"/>
             <xsl:with-param name="end-number" select="$end-number"/>
             <xsl:with-param name="index" select="$index"/>
           </xsl:call-template>
         </xsl:when>
         <xsl:when test="$start-number = $nodes[1]">
           <xsl:call-template name="show-missing">
             <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
             <xsl:with-param name="start-number" select="$start-number + 1"/>
             <xsl:with-param name="end-number" select="$end-number"/>
             <xsl:with-param name="index" select="$index"/>
           </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
           <obj>
             <childnode>
               <xsl:value-of select="$start-number"/>
             </childnode>
           </obj>
           <xsl:call-template name="show-missing">
             <xsl:with-param name="nodes" select="$nodes"/>
             <xsl:with-param name="start-number" select="$start-number + 1"/>
             <xsl:with-param name="end-number" select="$end-number"/>
             <xsl:with-param name="index" select="$index"/>
           </xsl:call-template>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:if>
   </xsl:template>
</xsl:stylesheet>

   The above works for the simple XML document given in the previous post 
because the string() of the obj node is the same as the string() of the 
only contained obj/childnode node.  What is the best way (or is there a 
way) to allow $index to be converted from a string to the XPath that the 
string represents?


Greg Faron
Integre Technical Publishing Co.



 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]