Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Group and Sequence combination in xslt 2.0 [Thread Next] Re: Group and Sequence combination in xslt 2.0To: NULL Date: 10/9/2008 4:41:00 AM On 9 Okt., 12:55, Martin Honnen <mahotr...@yahoo.de> wrote:
> RolfK wrote:
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<xsl:variable name=3D"vSeq">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<xsl:for-each-gr=
oup select=3D"SeqTest/Item"
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
group-by=3D"substring(.,1,string-length(.)-2)">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
<xsl:variable name=3D"vBaseName" s
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
elect=3D"substring(.,1,string-length(.)-2)"/>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
<xsl:if test=3D"$vBaseName !=3D 'nepumuk'">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0<xsl:sequence select=3D"$vBaseName"/>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
</xsl:if>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xsl:for-each-g=
roup>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xsl:variable>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<Seq>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<xsl:for-each se=
lect=3D"$vSeq">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
<Item BaseName=3D"{.}"/>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</xsl:for-each>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</Seq>
> > =A0 =A0<Seq>
> > =A0 =A0 =A0 =A0 =A0 =A0<Item BaseName=3D"ottokarl"/>
> > =A0 =A0</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:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xsl:variable name=3D"vSe=
q" as=3D"xs:string*">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xsl:for-=
each-group select=3D"SeqTest/Item"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 group-by=3D"substring(.,1,string-length(.)-2)">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 <xsl:variable name=3D"vBaseName"
> select=3D"substring(.,1,string-length(.)-2)"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 <xsl:if test=3D"$vBaseName !=3D 'nepumuk'">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 <xsl:sequence select=3D"$vBaseName"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 </xsl:if>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </xsl:for=
-each-group>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </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=3D"SeqTest/Item"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 group-by=3D"substring(.,1,string-length(.)-2)">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 <xsl:variable name=3D"vBaseName" select=3D"current-grouping-key()"/=
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 <xsl:if test=3D"$vBaseName !=3D 'nepumuk'">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 <xsl:sequence select=3D"$vBaseName"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 </xsl:if>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </xsl:for=
-each-group>
>
> or you could get rid of the variable completely:
>
> <xsl:for-each-group select=3D"SeqTest/Item"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 group-by=3D"substring(.,1,string-length(.)-2)">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 <xsl:if test=3D"current-grouping-key() !=3D 'nepumuk'">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 <xsl:sequence select=3D"current-grouping-key()"/>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 </xsl:if>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </xsl:for=
-each-group>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
Dear Martin,
Thanks a lot for this substancial and quick help !
I guess it will improve my code and even the key might inprove the
overall performance.
Rolf
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
