Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Group and Sequence combination in xslt 2.0

From: Martin Honnen <mahotrash@-----.-->
To: 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/


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