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

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

Subject: Re: Generating a list of items NOT present in source XML
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Fri, 17 May 2002 16:27:49 -0600
msxsl missing
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


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.