Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Group and Sequence combination in xslt 2.0 >Thread Next - Re: Group and Sequence combination in xslt 2.0 Re: Group and Sequence combination in xslt 2.0To: NULL Date: 10/9/2008 12:56:00 PM
RolfK wrote:
> <xsl:variable name="vSeq">
> <xsl:for-each-group select="SeqTest/Item"
> group-by="substring(.,1,string-length(.)-2)">
> <xsl:variable name="vBaseName" s
> elect="substring(.,1,string-length(.)-2)"/>
> <xsl:if test="$vBaseName != 'nepumuk'">
> <xsl:sequence select="$vBaseName"/>
> </xsl:if>
> </xsl:for-each-group>
> </xsl:variable>
> <Seq>
> <xsl:for-each select="$vSeq">
> <Item BaseName="{.}"/>
> </xsl:for-each>
> </Seq>
> <Seq>
> <Item BaseName="ottokarl"/>
> </Seq>
> </DEBUG>
>
> As you can see the result element Item is only once there.
> For me it meas that I have not build a sequnce of simple string values
> over which I want to iterate.
The variable is currently a temporary tree. If you want a sequence of
strings then you need to use the 'as' attribute as follows:
<xsl:variable name="vSeq" as="xs:string*">
<xsl:for-each-group select="SeqTest/Item"
group-by="substring(.,1,string-length(.)-2)">
<xsl:variable name="vBaseName"
select="substring(.,1,string-length(.)-2)"/>
<xsl:if test="$vBaseName != 'nepumuk'">
<xsl:sequence select="$vBaseName"/>
</xsl:if>
</xsl:for-each-group>
</xsl:variable>
Not related to your problem is the following suggestion: instead of
computing the "base name" again and again you can simply call the
current-grouping-key() function e.g.
<xsl:for-each-group select="SeqTest/Item"
group-by="substring(.,1,string-length(.)-2)">
<xsl:variable name="vBaseName" select="current-grouping-key()"/>
<xsl:if test="$vBaseName != 'nepumuk'">
<xsl:sequence select="$vBaseName"/>
</xsl:if>
</xsl:for-each-group>
or you could get rid of the variable completely:
<xsl:for-each-group select="SeqTest/Item"
group-by="substring(.,1,string-length(.)-2)">
<xsl:if test="current-grouping-key() != 'nepumuk'">
<xsl:sequence select="current-grouping-key()"/>
</xsl:if>
</xsl:for-each-group>
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
