[xsl] Problem involving position() and COnditional filtering

Subject: [xsl] Problem involving position() and COnditional filtering
From: "Pankaj Bishnoi" <pankaj.bishnoi@xxxxxxxxxxx>
Date: Tue, 30 May 2006 15:28:07 +0530
Hi All
        I am facing a issue while using position() function with conditional
filtering.  My Source xml is:::


<?xml version="1.0" encoding="UTF-8"?>
<NounOutcome>
    <DocumentIds>
        <DocumentIdType>
            <Id>Id10</Id>
            <Revision>Revision11</Revision>
        </DocumentIdType>
        <DocumentIdType>
            <Id>43</Id>
            <Revision>Revision14</Revision>
        </DocumentIdType>
       <DocumentIdType>
            <Id>Id10</Id>
            <Revision>Revision11</Revision>
        </DocumentIdType>
        <DocumentIdType>
            <Id>43</Id>
            <Revision>Revision14</Revision>
        </DocumentIdType>
    </DocumentIds>
    <NounOutcomeValue>NounOutcomeValue17</NounOutcomeValue>
    <UserArea>UserArea18</UserArea>
</NounOutcome>


and the xsl is

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.1" xmlns:java="http://xml.apache.org/xslt/java";
xmlns="http://www.openapplications.org/oagis";
xmlns:str="http://exslt.org/strings";
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect">
     <xsl:output method="xml" version="1.0" encoding="ISO-8859-1"
indent="yes"/>
     <xsl:template match="/">
          <NounOutcome>
               <DocumentIds>
                    <xsl:for-each
select="/NounOutcome/DocumentIds/DocumentIdType">
                         <xsl:if test="Id=&apos;43&apos;">
                              <DocumentIdType>
                                   <Id>
                                        <xsl:value-of select="Id"/>
                                   </Id>
                                   <Revision>
                                        <xsl:value-of select="position()"/>
                                   </Revision>
                              </DocumentIdType>
                         </xsl:if>
                    </xsl:for-each>
               </DocumentIds>
               <NounOutcomeValue>
                    <xsl:value-of select="/NounOutcome/NounOutcomeValue"/>
               </NounOutcomeValue>
               <UserArea></UserArea>
          </NounOutcome>
     </xsl:template>
</xsl:stylesheet>


Now here in the XSL i am filtering the source DocumentIdType record based on
Id value. The problem is that the position function generates value
according to the source xml occurrences and not the actual occurrence in
output. So for two matching record I get the output value in Revision field
as 2,4 but I want 1,2.

The output generated is


<?xml version="1.0" encoding="UTF-8"?>
<NounOutcome xmlns="http://www.openapplications.org/oagis";
xmlns:java="http://xml.apache.org/xslt/java";
xmlns:str="http://exslt.org/strings";>
    <DocumentIds>
        <DocumentIdType>
            <Id>43</Id>
            <Revision>2</Revision>
        </DocumentIdType>
        <DocumentIdType>
            <Id>43</Id>
            <Revision>4</Revision>
        </DocumentIdType>
    </DocumentIds>
    <NounOutcomeValue>NounOutcomeValue17</NounOutcomeValue>
    <UserArea/>
</NounOutcome>


Is there any other way to generate  such sequence.


Thanks in advance for any help!

Thanks
Pankaj

Current Thread