Re: normalize as part of a 'select-distinct' in a for-each?

Subject: Re: normalize as part of a 'select-distinct' in a for-each?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 4 Oct 1999 13:04:58 +0100 (BST)
 

]   <xsl:for-each select="//c[not(normalize(text())
]                           =normalize(following::c/text()))]" >

You are making it hard for yourself by using for-each here, as then the
current node of the expression is the document root. You need to
get access to a c node and a following c node, and within a single
select expression the only way to do that is to arrange that one of them
is the current node.

This version uses apply-templates (and still works if you replace some
 <c>X</c> by <c> X   </c>, I just tried)

If this would clash with some other template for c then you could add
mode attributes to distinguish this processing.

David

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
                xmlns:xt="http://www.jclark.com/xt";
                extension-element-prefixes="xt">

  <xsl:template match="root">
     <xsl:apply-templates select="//c">
     <xsl:sort select="normalize(.)"/>
     </xsl:apply-templates>
  </xsl:template>


  <xsl:template match="c">
   <xsl:if test="not(following::c[normalize(.)=normalize(current())])">
   <xsl:value-of select="normalize(.)"/>
   </xsl:if>
  </xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread