Thank you Michael. I wasn't aware of the xsl:where-populated instruction.
That solves the problem in a clean way for me.
-----Original Message-----
From: Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, August 3, 2022 3:35 AM
To: xsl-list <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: Algorithm for setting a variable number of attributes
A variant of this is to use xsl:where-populated:
> <xsl:analyze-string select="." regex="^SUBTASK
(\d+)-(\d+)-(\d+)-((\d+)-(\d+) - \((\d+)\))?$">
> <xsl:matching-substring>
<xsl:where-populated>
> <xsl:attribute name="chapnbr" select="regex-group(1)"/>
> <xsl:attribute name="sectnbr" select="regex-group(2)"/>
> <xsl:attribute name="subnbr" select="regex-group(3)"/>
> <xsl:attribute name="func" select="regex-group(4)"/>
> <xsl:attribute name="seq" select="regex-group(5)"/>
> <xsl:attribute name="revdate" select="regex-group(6)"/>
</xsl:where-populated>
> </xsl:matching-substring>
> </xsl:analyze-string>
>
The xsl:where-populated instruction filters out any attributes whose string
value would be zero-length.
Michael Kay
Saxonica
|