Re: [xsl] rather tricky numbering problem

Subject: Re: [xsl] rather tricky numbering problem
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 21 Jun 2010 19:27:05 +0100
Looks like a fairly simple grouping problem, combined with handling multiple input and output files.

<xsl:for-each-group select="collection('folder')" group-by="/*/product-num/substring(., 1, 5)">
<xsl:choose>
<xsl:when test="count(current-group() gt 1)">
<xsl:for-each select="current-group()">
<xsl:apply-templates select=".">
<xsl:with-param name="new-prod-num" select="concat(current-grouping-key(), position()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select=".">
<xsl:with-param name="new-prod-num" select="current-grouping-key()"/>
</xsl:apply-templates>
</
</
</


Michael Kay
Saxonica

On 21/06/2010 18:31, a kusa wrote:
Hello

I have a requirement which  I am not sure if this can be done in XSLT.
I will try to explain it  theoretically as much as possible and please
let me know if there is any way this can be done in XSLT.

I have a bunch of XML files in a folder.

The XML files have an element called 'prod-num' which is an 8-digit
number the first 5 of which follows a particular numbering scheme
based on what the XML is for.

For example, if the XML represents books for children,  the prod-num
has the following numbering scheme : 1212 - 1.
If the XML data represents books for Science, the prod-num has the
following numbering scheme: 1212-2

Now, here is what needs to happen.

The last three of the prod-num needs to be sequentially numbered if
the first 5 are the same.

So, in my explained example above, the transformation needs to read
the folder with the XML files, and read through the prod-num values.

If there are say two XML files with 1212-1, then the first one needs
to be updated with 1212-1001, the second one becomes 1212-1002.

Can the experts please give me some tips and ideas to resolve this?

Thanks in advance

Current Thread