Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Group and Sequence combination in xslt 2.0

From: RolfK <Rolf.Kemper@--.-----.--->
To: 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent